上传图片失败
发布于 6 年前 作者 xiongyang 6443 次浏览 来自 问答

上传图片报错

{errMsg: “uploadFile:fail Error: read ECONNRESET”}

代码:

var that = this;

wx.showLoading({

title: ‘图片处理中’,

})

wx.uploadFile({

url: ’ url’, //开发者服务器的 url

//  url: this.data.reqUrl,

filePath: that.data.src, // 要上传文件资源的路径 String类型!!!

name: ‘filename’, // 文件对应的 key ,(后台接口规定的关于图片的请求参数)

header: {

‘content-type’: ‘multipart/form-data’

}, // 设置请求的 header

formData: {}, // HTTP 请求中其他额外的参数

success: function (res) {

console.log(res);

var respon = res.data;

var str = JSON.parse(respon);

console.log(str.path);

var pth = str.path;

pth = pth.replace(‘image\\’,’’);

console.log(pth);

//var imgp = that.data.imgdir + pth;

that.setData({

imgpath:imgp

})

wx.hideLoading();

// that.downloadImage(pth);

},

fail: function (res) {

console.log(res);

}

})

回到顶部