带有React的POST多部分文件 [英] POST muiltiple multipart file with React
本文介绍了带有React的POST多部分文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将此问题放在参考中使用React发布文件.js
I put this questions in reference POST a file with React.js
我现在想将文件列表发送到端点.
I would like now to send a list of files to the endpoint.
我的输入组件:
<input onChange={(e) => Actions.uploadXLS(e.target.files)} multiple type="file" name="xlsz" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" style={{ display: 'none' }}/>
动作处理程序:
uploadXLS(files) {
let i = 0;
const data = new FormData();
for ( i = 0; i < files.length; i++ ) {
data.append( 'file' , files[i]);
}
console.log(data);
this.getInstance().callUploadXLS( data );
}
控制台打印:FormData {}
console prints: FormData{}
推荐答案
File file = new File("/Users/user1/Documents/VendorDbResources/ExcelFileCore-1.xlsx");
FileInputStream input = new FileInputStream(file);
MultipartFile multipartFile1 = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input));
file = new File("/Users/user1/Documents/VendorDbResources/ExcelFileCore-2.xlsx");
input = new FileInputStream(file);
MultipartFile multipartFile2 = new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input));
MultipartFile[] arrayOfMultipartFile = {multipartFile1, multipartFile2};
if (arrayOfMultipartFile.length > 0)
return vendorService.readExcelFile(arrayOfMultipartFile);
else
return null;
我已经尝试了使用静态数据的后端功能.在上面,您可以看到我创建了一个包含多个部分的文件数组并提供给服务实现.
I have tried backend functionality with static data.above you can see i created an array of multipart file and provided to the service implementation.
工作正常.条目也可以在db中看到.
And it's working fine. Entries can be seen in db as well.
这篇关于带有React的POST多部分文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文