我想使用RTK查询将带有表单数据的图像发送到Nest JS服务器,但文件未发送。代码如下:
uploadImage: builder.mutation<any, any>({
query: (imageFile) => {
var bodyFormData = new FormData();
bodyFormData.append('file', imageFile);
console.log({ bodyFormData, imageFile });
return {
url: '/uploader/image',
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data;'
},
body: { bodyFormData }
};
}
})
我可以用Axios发送图片,但在 RTK 中却不能。
Content-Type
应该从headers
中省略,因为如果formData
为true
,它会自动添加正确的边界。 - undefined