苹果手机调用wx.uploadFile无法获取response的header
发布于 5 年前 作者 songwei 9039 次浏览 来自 问答

当苹果手机上调用wx.uploadFile时,success回调函数输出结果中没有header信息

在微信开发者工具和安卓手机上都可以得到header信息,

我想从header中获取如Set-Cookie这样的重要信息。

苹果手机返回数据如下:

data:“xx”

errMsg:“uploadFile:ok”

statusCode:200

安卓和开发工具返回如下:

data:“xx”

errMsg:“uploadFile:ok”

header:{Server: “nginx/1.14.0”, Date: “Fri, 01 Mar 2019 07:32:32 GMT”, Content-Type: “application/json;charset=UTF-8”, Transfer-Encoding: “chunked”, Connection: “close”}

statusCode:200

代码!!!!

index.wxml

<view class=“weui-uploader__input” bindtap=“chooseImage”>点我上传</view>

index.js

Page({

data: {

},

onLoad: function (options) {

},

chooseImage: function (e) {

wx.chooseImage({

sizeType: [‘original’, ‘compressed’], // 可以指定是原图还是压缩图,默认二者都有

sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有

success: function (res) {

let tempFilePath = res.tempFilePaths[0];

wx.uploadFile({

url: http://www.baidu.com,

filePath: tempFilePath,

name: ‘file’,

formData: {},

success(res) {

console.log(res);

}

})

}

})

}

})

3 回复

请提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

https://developers.weixin.qq.com/miniprogram/dev/api/wx.uploadFile.html

接口文档中只定义了data和statusCode, 请不要利用接口文档中未定义的返回值

我今天也遇到了,机型iphone5cc, 微信版本库7.0.2, 基础库版本为2.6.1。然后我调低基础库的版本到2.4.4,就又可以了,希望有帮助

回到顶部