upload file
This commit is contained in:
@@ -12,23 +12,26 @@ const common = {
|
||||
/**
|
||||
* 上传文件(只能单文件上传)
|
||||
* @param { String } url 服务器 url
|
||||
* @param { String } name 上传类型 goods-商品图片 avatar-用户头像 video-视频 store_logo-店铺logo store_banner-店铺banner store_avatar-店铺头像
|
||||
* @param { String } filePath 要上传文件资源的路径
|
||||
* @param { String } type 上传文件验证类型 默认: img 可选: video
|
||||
* @return { object } promise 对象 resolve 返回文件服务器地址 reject 返回错误信息
|
||||
*/
|
||||
uploadFile({ url, filePath, type = 'img' } = {}) {
|
||||
uploadFile({ url, name, filePath }) {
|
||||
const token = uni.getStorageSync('token');
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: url,
|
||||
header: { "authorization": 'Bearer' + " " + token },
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
formData: { type: type },
|
||||
name: name,
|
||||
formData: {
|
||||
name: name,
|
||||
},
|
||||
success: uploadFileRes => {
|
||||
const data = JSON.parse(uploadFileRes.data);
|
||||
// console.log(data);
|
||||
if(data.errCode == 0) {
|
||||
resolve(data.data.url);
|
||||
resolve(data.data);
|
||||
} else {
|
||||
reject(data.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user