片时,错误:发送照片后无法设置标题,"/>
上传照片时,错误:发送照片后无法设置标题,
我试图通过api上传照片,此api使用axios消耗了另一个api,但是当我使用api上传时,它给出了错误:
错误:发送后无法设置标题,
当我在axios进程将错误抛出到catch块后调试res.status时
我想念东西吗,这是代码:
upload: async (req, res) => {
const { subscriberId } = req.query;
const file = req.file;
if (!file) {
return res
.status(httpStatus.forbidden)
.json({
message: 'No File Found'
});
}
try {
const form = new FormData();
// console.log(form);
form.append('file',
file.buffer,
file.originalname
);
await axios.post(`${config.get('UPLOAD_PHOTO')}?subscriberId=${subscriberId}`, form,
{
headers: {
'api-key': `${config.get('API_KEY_CORE_SERVICE')}`,
'Request-Id': req.requestId,
'Content-Type': `multipart/form-data; boundary=${form._boundary}`
}
})
.catch((error) => {
// console.log(error.response.data)
res.status(httpStatus.internalServerError).json({
success: false,
message: error.message,
code: errorCodes.internalServerError
});
});
return res.status(httpStatus.ok).json({
success: true,
status: httpStatus.ok,
message: 'Successfully Upload Photo',
});
} catch (e) {
return res.status(e.statusCode || httpStatus.internalServerError).json({
success: false,
message: (e.error && e.error.message) || e.message || e,
code: errorCodes.internalServerError
});
}
回答如下:您可以删除它
更多推荐
上传照片时,错误:发送照片后无法设置标题,
发布评论