【紧急】图片上传问题
发布于 5 年前 作者 lei15 7767 次浏览 来自 问答

小程序图片上传,本地编辑器上传没问题。

发布体验版后,图片上传服务器出现异常。

本地上传的时候小程序返回的路径是http的,体验版用手机测试后图片地址返回的是wxfile://开头的,跟开发版完全不一样,求助各位大神援助,着急~!~!~!

本地模拟器:

真机:

4 回复

这样看是看不出问题的,我的多图上传正式版跟体验版跟开发版都没有问题,贴图片以及,代码给你参考一下

// 上传图片

chooseImg: function () {

var that = this;

var selectImg = that.data.selectImg;

wx.chooseImage({

count: 6,

sizeType: [‘original’, ‘compressed’],

sourceType: [‘album’, ‘camera’],

success: function (res) {

var tempFilePaths = res.tempFilePaths

wx.showLoading({

title: ‘正在上传…’,

})

for (var i = 0; i < tempFilePaths.length; i++) {

wx.uploadFile({

url: app.data.apiUrl + ‘/api/property/uploadimg’,

filePath: tempFilePaths[i],

name: ‘file’,

formData: {

app_token: app.data.member.app_token,

},

success: function (res) {

var data = JSON.parse(res.data)

that.data.selectImgPath.push(data.data.path)

}

})

}

setTimeout(function(){

wx.hideLoading()

},2000)

if (tempFilePaths.length + selectImg.length > 6) {

wx.showToast({

title: ‘最多只能上传6张图片’,

icon: ‘none’,

duration: 2000

})

} else {

for (var i = 0; i < tempFilePaths.length; i++) {

selectImg.push(tempFilePaths[i])

}

that.setData({

selectImg: selectImg,

selectImgType: false,

})

}

},

fail: function () {

that.tips(‘选取图片失败’)

}

})

},

我这个是跟表单一起提交的,提交的时候只需要提交that.data.selectImgPath这个数组里面的路径上去就可以了

想问下,服务器如何接受图片并保存啊?

跟你遇到的问题一样,小程序没有合适的图片插件。

求助大神啊

回到顶部