上传超过2m的文件服务器报错,wx.uploadFile文件上传 小于2M文件上传正常,大于2M报错,需使用哪个api解决该问题?...

上传文件大于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 ()

6bf11a3fceb9bd7616cafeb027dd0a85.png

附代码:

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

}

}

)

// }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值