在选择图片后使用wx.getFileSystemManage.readFile转化base64是出现报错:VM22195:1 readFile:fail parameter error: parameter.filePath should be String instead of Undefined
实在想不通啊!
代码如下:
user.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
})
.then(res=>{
// 选择图片成功,开始上传
// 这里res是可以打印出来的
console.log(res)
//var filePath = res.tempFilePaths[0]
return user.getFileSystemManagerReadFile({
filePath: res.tempFilePaths[0], // 这里出现问题
encoding: 'base64'
})
})
.then(res=>{
console.log('base64', res)
})
.catch(err=>{
console.log('头像更新错误:', err)
})
我的不报错
static getFileSystemManagerReadFile() {
return new Promise((resolve, reject) => wx.getFileSystemManager().readFile({ success: resolve, fail: reject }));
}
/*
* Promise化API
*/
const app = getApp()
class User {
// 判断授权
static getSetting() {
return new Promise((resolve, reject) => wx.getSetting({ success: resolve, fail: reject }));
}
// 获取原生用户信息
static getUserInfo() {
return new Promise((resolve, reject) => wx.getUserInfo({ success: resolve, fail: reject }));
}
// 上传图片
static chooseImage() {
return new Promise((resolve, reject) => wx.chooseImage({ success: resolve, fail: reject }));
}
// base64 读取本地文件
static getFileSystemManagerReadFile() {
return new Promise((resolve, reject) => wx.getFileSystemManager().readFile({ success: resolve, fail: reject }));
}
}
export default User;