我的传奇成功将文件附件发布到api,但仍然捕获到错误,告诉用户附件未上传。我的控制台日志还显示了捕获情况。
这是我的代码...这里显然有什么不对吗?
const postFileUpload = async (payload) => {
let data = {};
var accessToken = gapi.auth.getToken().access_token; // Here gapi is used for retrieving the access token.
try {
const { id, campDate, type, file } = payload;
const formData = new FormData();
formData.append('file', file);
formData.append('type', type);
if (campDate !== undefined) {
formData.append('campDate', campDate);
}
formData.append('id', Id);
const response = await axios.post(
`https://${API_ENDPOINT}/attachments`,
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer ' + accessToken
}
}
);
console.log('SUCCESS!!');
if (!response.success) {
throw new Error(response.erorrMessage);
}
data = response.data;
return data;
} catch (error) {
console.log('FAILURE!!', error);
console.error('Error uploading attachment');
throw new Error(error);
}
}
答案 0 :(得分:0)
您确定来自通话后的回复具有.success
属性吗?
我将改为查看状态码。