upload.js
797 字节
import {
baseURL
} from './request.js'
import {
toast,
toa
} from './toast.js'
export const uploadFile = (tempFilePaths, data) => {
return new Promise((resolve, reject) => {
toa.loading('上传中..')
uni.uploadFile({
url: baseURL + '/common/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths,
name: 'file',
formData: {
...data,
token: uni.getStorageSync('token') || ''
},
success: (res) => {
toa.hideLoading()
console.log(res);
if (res.statusCode == 200) {
// return res
resolve(JSON.parse(res.data).data)
}
},
fail: (err) => {
toa.hideLoading()
toast(JSON.parse(err.data).msg)
console.log(err, '上传报错');
// return
reject(err)
}
})
})
}