上传文件大于2M,提示错误信息,(提示与json格式无关,是api内部限制了上传文件大小),需用哪个api能解决上传文件大小问题(上传文件格式,pdf,word,xlsx,ppt)
Unexpected token < in JSON at position 0;at api uploadFile success callback function
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at success (http://127.0.0.1:15704/appservice/pages/panel/panel.js:264:32)
附代码:
wx.chooseMessageFile({
count: 1,
//type: ‘file’,
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
console.log(“res:”, res)
const tempFiles = res.tempFiles;
var fileinfo = tempFiles[0]// tempFiles[idx]
console.log(“fileinfo:”, fileinfo);
wx.uploadFile({
header: {
‘content-type’: ‘multipart/form-data’,
//‘Content-Type’: ‘application/x-www-form-urlencoded’
},
// method: ‘POST’,
// header: { ‘content-type’: ‘application/x-www-form-urlencoded’ },
url: constant.root_upload_url,
filePath: fileinfo[‘path’],
name: ‘file’,
formData: {
‘userid’: userid,
‘menuid’: currentMenuId,
‘filename’: fileinfo[‘name’],
},
success(res) {
const t_data = res.data
var jsonObj = JSON.parse(t_data);
//刷新文件列表
if (!jsonObj[‘errorFlag’]) {
wx.showModal({
title: ‘提示信息’,
content: jsonObj.errorMsg,
})
} else {
//上传成功,刷新文件列表
that.reloadFolderList(currentMenuId);
}
},
error(error) {
console.log(“error:”, error)
wx.showModal({
title: ‘提示信息’,
content: ‘抱歉,数据解析异常,请稍后重试!’,
})
//do something
}
}
)
// }