小程序里面视频上传功能,走到了catch,解析返回数据失败那块,这是打印的地方,什么原因呢?
//点击上传视频按钮
upLoadVideoEvent(){
//选择视频
wx.chooseVideo({
sourceType: ['album', 'camera'], // 可从相册或相机选择
maxDuration: 60, // 最长拍摄时间,单位秒
camera: 'back', // 默认使用后置摄像头
success: (res) => {
console.log(res,'选择的视频');
//视频时长不能超过一分钟
const maxDuration = 60; //最大允许时长,单位秒
if(res.duration > maxDuration){
wx.showToast({
title: '视频时长不能超过1分钟',
icon:'none'
})
return;
}
//视频大小不能超过500M
const maxSize = 500*1024*1024
if(res.size>maxSize){
wx.showToast({
title: '视频大小不能超过500M',
icon:'none'
})
return;
}
console.log('选择视频成功',wx.getStorageSync('jsessionid'), res)
this.setData({
// videoUrl: res.tempFilePath,
uploadResult: null, // 重置上传结果
upLoadVideoState:1, //视频选择成功,状态变成上传中
})
//上传视频
this.setData({
isUploading: true,
progress: 0
})
console.log(res.tempFilePath,'res.temmp')
// 后端上传接口
const uploadTask = wx.uploadFile({
url: `${this.data.baseUrl}/file/upload`,
filePath: res.tempFilePath,
name: 'file', // 对应后端接收文件的参数名
header: {
// 'content-type': 'multipart/form-data',
jsessionid: wx.getStorageSync('jsessionid')
},
// formData: {
// // 可以添加其他表单数据
// 'user': 'test'
// },
success:async (res) => {
console.log('上传成功', res)
// wx.hideLoading()
try {
const data = JSON.parse(res.data)
console.log(data,'解析data')
if(data?.code){
wx.showToast({
title: data?.message,
icon: 'none'
})
this.setData({
videoUrl: '',
videoUrlUpload:'',
uploadResult: null, // 重置上传结果
upLoadVideoState:0, //视频选择成功,状态变成上传中
})
//如果是401未授权,重新登录,
if(data?.code == '401'&&data?.message== '未授权,请先登录'){
//登录过期
await this.unloginEvent();
this.upLoadVideoEvent();
return;
}
}else{
const jsessionid = wx.getStorageSync('jsessionid');
const videoU =data?.url?.indexOf('?')!= -1?data?.url?.split('?')[0]+'?JSESSIONID='+`${jsessionid}`:data?.url+'?JSESSIONID='+`${jsessionid}`
console.log(videoU,"videoU")
this.setData({
videoUrl:videoU,
videoUrlUpload:data.url,
})
console.log(this.data.videoUrl,this.data.videoUrlUpload,"vvv")
this.setData({
uploadResult: {
success: true,
videoId: data.videoId || 'unknown'
},
isUploading: false
})
wx.showToast({
title: '上传成功',
icon: 'success'
})
}
} catch (e) {
console.log(e,"e")
this.handleUploadError('解析返回数据失败')
}
},
fail: (err) => {
console.error('上传失败', err)
// wx.hideLoading()
this.handleUploadError('上传失败,请重试')
}
})
// 监听上传进度
uploadTask.onProgressUpdate((res) => {
console.log('上传进度', res.progress)
this.setData({
progress: res.progress
})
// 当进度更新时隐藏初始加载提示
if (res.progress > 0) {
wx.hideLoading()
}
})
},
fail: (err) => {
console.error('选择视频失败', err)
this.setData({
// upLoadVideoState:0, //视频选择失败,状态为0,
})
wx.showToast({
title: '选择视频失败',
icon: 'none'
})
}
})
},
// 处理上传错误
handleUploadError(message){
this.setData({
isUploading: false,
uploadResult: {
success: false,
message: message
},
upLoadVideoState:0,
videoUrl:'',
videoUrlUpload:'',
progress:0,
})
wx.showToast({
title: message,
icon: 'none'
})
},

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)