wx.cloud.uploadFile使用自定义文件路径报错
发布于 6 年前 作者 wanjuan 2012 次浏览 来自 问答

wx.chooseImage获取的filePath 存入全局变量that.data.localPath,

uploadFile 和全局变量会报错,确认这两个变量是一样的。

想知道是不是bug

var that = this

// 选择图片

wx.chooseImage({

count: 1,

sizeType: [‘compressed’],

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

success: function (res) {

const filePath = res.tempFilePaths[0]

console.log(filePath)

that.setData({          //!!!!!通过that访问

localPath: res.tempFiles[0].path//将下载下来的地址给data中的变量

});

wx.showLoading({

title: ‘上传中’,

})

const cloudPath = that.data.cloudPath

const localPath = that.data.localPath

console.log(filePath)

console.log(localPath)

if (filePath === localPath) {

console.log("===")

}

//console.log(cloudPath)

wx.cloud.uploadFile({

cloudPath,

localPath, // 文件路径

}).then(res => {

wx.hideLoading()

console.log(’[上传文件] 成功:’, res)

console.log(res.fileID)

}).catch(error => {

console.error(’[上传文件] 失败:’, error)

wx.showToast({

icon: ‘none’,

title: ‘上传失败’,

})

// handle error

})

}

})

回到顶部