openVideoChoose() {
let that = this;
uni.chooseFile({
count: 1,
success: (res) => {
if(res.size > 5010241024) {
toast("视频大小不能超过50M")
return;
}
console.log(JSON.stringify(res))
//#ifdef MP-WEIXIN
that.videoFormData.tempFilePath = res.tempFilePath;
//#endif
//#ifdef H5
that.videoFormData.tempFilePath = res.tempFilePaths[0];
//#endif
}
})
},
uploadVideo() {
let that = this;
if (that.videoFormData.title==null || !that.videoFormData.title.trim()) {
toast('请输入视频标题!');
return false;
}
if (!that.videoFormData.tempFilePath) {
toast('请选择视频!');
return false;
}
uni.showLoading({title: "上传中,请稍等"})
uni.uploadFile({
filePath: that.videoFormData.tempFilePath,
url: config.baseUrl + '/uploadCategoryVideo',
name: 'file',
formData: {
type: that.activeBtn,
title: that.videoFormData.title
},
header: {
"Content-Type": "multipart/form-data",
'X-Authorization': getToken()
},
success: function (res1) {
uni.hideLoading();
var reJet = JSON.parse(res1.data);
if (reJet.code == 0) {
that.videoPopupClose();
that.init();
toast('添加成功!')
} else {
that.videoPopupClose();
toast('添加失败!' + reJet.message)
}
},
fail: function (err) {
uni.hideLoading();
toast('添加失败!')
}
});
},
1 个回复
JXWang
可以试试把 "Content-Type": "multipart/form-data" 去掉行不行,参考文档