import {
	mainUrl
} from './baseUrl';
let fileBaseurl = mainUrl + '/api/upload/image' //你的图片上传地址

export function uploadImg(url, token) { // 传参是$event
	/*
    let img1 = event.target.files[0];
    let type = img1.type;
    let size = img1.size;
    let typelist = 'image/jpeg, image/png, image/jpg'
    if (typelist.indexOf(type) === -1) {  
        alert('支持上传的图片格式不对')
        return false;  
    }
    if (size>5242880) {  
        alert('上传图片不能大于5m')
        return false;  
    }  
    let form = new FormData();
    form.append('file',img1);
	*/

	return new Promise((resolve, reject) => {
		let a = uni.uploadFile({
			url: fileBaseurl, // 仅为示例，非真实的接口地址
			filePath: url,
			name: 'file',
			formData: {
				user: 'test'
			},
			header: {
				'Authorization': 'bearer ' + token
			},
			success: (res) => {
				//setTimeout(() => {
					resolve(res.data)
				//}, 1000)
			},
			fail: function(res) {
				reject(res.data)
			}
		});
	})

}
