uniapp中的uni-file-picker组件多图上传问题
uniapp中的uni-file-picker组件多图上传问题(同步方法)
https://blog.csdn.net/m0_67391120/article/details/123431870
默认file值以formData格式传输,header中不需要配置Content-Type,若配置Content-Type,传输发生错误
async uploadImg(tempFilePaths, token) {
console.log(token)
if (!tempFilePaths.length) return;
const path = tempFilePaths.pop();
this.filePathsList.push({url:path,name:""})
const [err, {data}] = await uni.uploadFile({
url: 'https://localhost/file/api/uploadtemp',
filePath: path,
name: 'file',
header: {
Authorization: token,
"Content-Type": "multipart/form-data",
}
});
console.log("err", err)
console.log("data", data)
if (!this.isGuid(data)) {
// upload fail
this.filePathsList.pop()
uni.showToast({
title: "上传失败",
icon: "none"
})
}else{
// upload success
this.filePathsList[this.filePathsList.length - 1].name = data
}
this.uploadImg(tempFilePaths,token);
},
Django 后台保存 uni-app 前端上传的图片
https://www.cnblogs.com/xsmile/p/12599535.html
uni.uploadFile({
url:your_url,
// header 注释掉
// header: {
// 'Content-Type': "multipart/form-data",
// },
filePath:that.imgList[0],
name:'imgs',
formData:{'uName': that.uName},
success(res) {
console.log('上传成功!')
}
})
def submitOrders(request):
img = request.FILES.get('imgs')
uName = request.POST.get('uName')
print(uName)
print('img:', img)
if img:
img_path = os.path.join('static/image/', img.name)
with open(img_path, 'wb') as fi:
for i in img.chunks():
fi.write(i)