我面临以下代码错误,即使在解决承诺之前,异步操作“FILE_UPLOAD_SUCCESS”也会发出,因此操作有效负载返回未定义。关于如何解决它的任何想法???
动作创建者
export const upload = (file) => {
return (dispatch)=>{
dispatch({type:"FILE_UPLOAD_START"})
return new Promise.resolve(()=>{
uploadDoc(file).then((hash)=>dispatch({type:"FILE_UPLOAD_SUCCESS",payload:hash}))
}).catch((err)=>{
dispatch({type:"FILE_UPLOAD_ERROR",payload:err})
})
}
}
上传文件
export const uploadDoc = (file) =>{
return new Promise((resolve,reject)=>{
var reader = new FileReader();
reader.readAsArrayBuffer(file[0]);
reader.onloadend = (evt) =>{
resolve(reader);
}
}).then((reader)=>{
return Promise.resolve(()=>{
const buffer = Buffer.from(reader.result);
ipfs.add(buffer)
.then((res)=>{
return res[0].hash;
})
})
})
}