这里用的是uniapp上传图片
<template>
<view class="upload" @click="selectType()">上传附件</view>
</template>
methods: {
selectType() {
uni.chooseImage({
count: 1, //默认9
sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: function(res) {
that.uploadImages(res.tempFilePaths);
}
});
},
uploadImages(tempFilePaths) {
let that = this;
let tmpLen = tempFilePaths.length;
let k = 0;
let succ = 0;
let fa = 0;
function uploadDo() {
uni.uploadFile({
url: "上传地址",
filePath: tempFilePaths[k],
name: 'files',
formData:{
file:tempFilePaths[k],
},
success: function(res) {
//成功处理
}
},
fail: function() {
fa++;
},
complete: function() {
k++;
if (k < tmpLen) {
uploadDo();
} else {
showToast("上传成功")
}
}
})
}
if (tmpLen > 0) {
uploadDo();
}
},
}
注意:需要在微信后台设置上传域名,否则上线后会出现上传失败

image.png