这是上传文件代码封装
function upload(options , callback){
// 选择图片进行上传
var that = this;
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: chooseImageRes => {
let tempFilePaths = chooseImageRes.tempFilePaths;
let tempFiles = chooseImageRes.tempFiles;
uni.showLoading({
title: '上传中...',
mask: true
});
uni.uploadFile({
url: that.serverUrl + '/source/uploadSource',
filePath: tempFilePaths[0],
name: 'file',
formData: {},
success: res => {
uni.showToast({
title:"上传成功"
})
if(callback){
var data = JSON.parse(res.data);
callback(data);
}
},
fail: function(err) {
uni.hideLoading();
uni.showToast({
title: '上传失败,请稍后重试!',
icon: 'none',
duration: 2000
});
}
});
uni.hideLoading();
}
});
}
module.exports = {
upload: upload
}
这是调用
uploadFile() {
var that = this;
that.$uploadFile({} , function(res){
if(res.code == 200){
that.woodSources.push(res.data)
}
})
},
DCloud_Android_DQQ
你留一下QQ. 提供一下 复现的代码和URL
2020-09-22 15:46
DCloud_Android_DQQ
你使用的哪个版本hbuilderx
2020-09-22 16:58
lam2015 (作者)
回复 DCloud_Android_DQQ: 510216104
2020-10-31 18:20