问题遇到的现象和发生背景
业务需求,将上传的图片转成base64格式传给后台
问题相关代码,请勿粘贴截图
base = path =>{
Taro.getFileSystemManager().readFile({
filePath: path,
encoding: 'base64',
success: res => {
console.log("base");
this.setState({
image_data:res.data
},()=>{
this.timestamp()
})
}
})
}
// 获取后台时间戳
timestamp = () => {
Taro.request({
url: 'https://iconvert-api.xunjietupian.com/api/v4/getutctime',
success: (res) => {
console.log("timestamp");
this.setState({
timestamp:res.data.utctime
},()=>{
this.getImageName()
})
}
});
}
// 获取文件名
getImageName = () =>{
console.log('getImageName');
let imagepath = this.state.imgurl;
let lastindex = imagepath.lastIndexOf('/')
let imageName = imagepath.substring(lastindex+1,imagepath.length)
this.setState({
image_name:imageName
},()=>{
this.datasign()
})
}