我试图通过上传文件选项(输入字段)从React应用程序发送formData,但Nest.JS端的formData为空。路由具有基于multer的装饰器,但数据被解析为未定义。
@UseInterceptors(FileInterceptor('excel'))
uploadFile(
@UploadedFile() excel: Express.Multer.File,
) {
console.log(excel) // undefined;
}const file = event.target.files?.item(0);
const formData = new FormData();
formData.append('excel', file);await axios.post(url, formData, {headers: {'Content-Type': 'multipart/form-data; boundary="X-TEST-BOUNDARY"'}});由于失眠/邮递员只调用服务而没有问题
BR、Igor
发布于 2021-09-07 21:58:07
在我的例子中,我们使用不带头部的axios和我们捕获的文件,如下所示:
const file = event.target.files[0]https://stackoverflow.com/questions/69088152
复制相似问题