iOS 手机上调用 wx.uploadFile 上传wxfile://temp_文件时出现错误,而在安卓手机和开发者工具模拟器上没有错误.
success和fail都没有发生回调,
报错如下:
MiniProgramError
o.replace is not a function. (In 'o.replace(/\;([^\s\;]*?(?=\=))/gi, ",$1")', 'o.replace' is undefined)
TypeError: o.replace is not a function. (In 'o.replace(/\;([^\s\;]*?(?=\=))/gi, ",$1")', 'o.replace' is undefined)
https://usr//app-service.js:6805:74
[native code]
h@https://lib/WAServiceMainContext.js:1:41822
anonymous@[native code]
https://usr//app-service.js:6806:39
https://lib/WAServiceMainContext.js:1:1120367
p@https://lib/WAServiceMainContext.js:1:399934
Cc@https://lib/WAServiceMainContext.js:1:873443
https://lib/WAServiceMainContext.js:1:1026394
p@https://lib/WAServiceMainContext.js:1:399934
Wh@https://lib/WAServiceMainContext.js:1:966481
forEach@[native code]
emit@https://lib/WAServiceMainContext.js:1:967122
c@https://lib/WAServiceMainContext.js:1:1027541
t_@https://lib/WAServiceMainContext.js:1:1028821
https://lib/WAServiceMainContext.js:1:1029406
https://lib/WAServiceMainContext.js:1:855581
https://lib/WAServiceMainContext.js:1:846662
emit@https://lib/WAServiceMainContext.js:1:356120
emit@[native code]
emit@https://lib/WAServiceMainContext.js:1:355739
subscribeHandler@https://lib/WAServiceMainContext.js:1:359225
[native code]
bug原因:
使用到weapp-cookie 包在iOS下对wx.uploadFile、wx.downFile读本地文件有兼容问题。
由于引用了weapp-cookie包,调用wx.downloadFile时,这个api会被包内部的downloadFileProxy改写掉,然后问题出在 miniprogram_npm\weapp-cookie\index.js 这个文件中 其中第2411行:
var responseCookies = response.header ? response.header['Set-Cookie'] || response.header['set-cookie'] : '';
通过这行语句拿到后端设置的cookie,在安卓系统中是一个字符串没有问题,但在IOS系统中是一个数组,所以在IOS系统的后续的replace操作中,对数组replace就会报错,安卓则不会。
解决方案:
weapp-cookie 更换成weapp-cookie2 , 文档:https://www.npmjs.com/package/weapp-cookie2