实现思路
- 选择文件
- 将文件上传到云存储
- 通过
downloadFile
获得文件路径tempFilePath
- 调用
readFileSync
根据步骤2的tempFilePath
读取文件(不直接读取本地文件是因为微信小程序只能在特定目录下读取本地文件,且考虑到小程序的通用性)
1. 选择文件wx.chooseMessageFile
wx.chooseMessageFile({
count: 1,
type: 'all',
success(res) {
console.log("选择文件成功", res)
},
fail(res) {
console.log("选择文件失败", res)
}
})
2. 将文件上传到云存储wx.cloud.uploadFile
wx.cloud.uploadFile({
cloudPath: res.tempFiles[0].name,
filePath:<