在此处使用fromData时遇到问题
const res = await axios.post(
clientPayload?.uploadLink,
{ data: formData },
{
headers: {
'content-type': 'multipart/form-data',
},
}
);
它与请求包一起工作,但与axios一起工作时,它显示了此错误。请提供任何帮助,这是我的函数
``
export const uploadVideo = async (title: string, file: any) => {
const formData = new FormData();
try {
const response = await axios.put(
`https://url.com/api/videos`,
{},
{
params: {
title,
},
headers: {
Authorization: `Apisecret ${process.env.VIDEO_SECRET}`,
Accept: 'application/json',
['Content-Type']: 'application/json',
},
}
);
const data = await response?.data;
const clientPayload = data?.clientPayload;
formData.append('policy', clientPayload?.policy);
formData.append('key', clientPayload?.key);
formData.append('x-amz-signature', clientPayload['x-amz-signature']);
formData.append('x-amz-algorithm', clientPayload['x-amz-algorithm']);
formData.append('x-amz-date', clientPayload['x-amz-date']);
formData.append('x-amz-credential', clientPayload['x-amz-credential']);
formData.append('success_action_status', '201');
formData.append('success_action_redirect', '');
formData.append('file', {
filepath: fs.createReadStream(file.path),
filename: file.path,
contentType: null,
});
const res = await axios.post(
clientPayload?.uploadLink,
{ data: formData },
{
headers: {
'content-type': 'multipart/form-data',
},
}
);
return res;
} catch (error) {
if (axios.isAxiosError(error)) {
logger.error('error message: ', error);
} else {
logger.error('unexpected error: ', error);
}
}
};
``
1条答案
按热度按时间brvekthn1#
尝试使用
URLSearchParams
而不是form-data
执行此操作