在 APP 中需要上传肖像,上传成功后,后台会给出上传后的信息,如下所示:
{
"code": 200,
"msg": "成功",
"data": {
"result": {
"number": 1,
"url": "https://xxx.jpg"
},
"message": "文件上传成功",
"status": 1
}
}
而在request.uploadFile的 then 方法中,只能拿到 uploadTask 或 TaskState的数据:
// 将本地应用文件上传至网络服务器
try {
request.uploadFile(context, uploadConfig)
.then((uploadTask: request.UploadTask) => {
uploadTask.on('complete', (taskStates: Array<request.TaskState>) => {
for (let i = 0; i < taskStates.length; i++) {
console.info(`upload complete taskState: ${JSON.stringify(taskStates[i])}`);
}
});
})
.catch((err: BusinessError) => {
console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
})
} catch (error) {
let err: BusinessError = error as BusinessError;
console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`);
}
我怎么才能拿到后台返给我的数据呢?
可以尝试下如下方法: