收藏
回答

wx.cloud.uploadFile使用自定义文件路径报错

框架类型 问题类型 终端类型 AppID 基础库版本
小程序 Bug 工具 wx1c3a08bef81382e3 2.6.1

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

})

}

})


回答关注问题邀请回答
收藏

1 个回答

  • 秋白
    秋白
    2020-03-11

    我就是路径没错 能打印出来 但是它就一直报错 说filePath undefined



    2020-03-11
    有用
    回复
登录 后发表内容