admin管理员组文章数量:1392105
I'm implementing a function which receives an excel file and parses its content then writes it into postgresql.
Considering requirment for a good througput for handing request, I decided using spring-webflux in springboot and coding in its reactive fashion.
Here is my code:
@PostMapping(value = "/import/excel")
public Mono<ApiResponse<ImportResult>> importExcel(@RequestPart("file") Mono<MultipartFile> file,
@RequestPart("modelName") String modelName) {
return file.flatMap(excel -> {
BatchUtils.excelValidate(excel);
try (InputStream inputStream = excel.getInputStream()) {
Class<?> excelHeaderClass = ExcelModel.classOf(modelName);
GenericExcelDataListener<?> excelDataListener = GenericExcelDataListener.build(excelHeaderClass, excelDataService);
// do read excel using excelDataListener
FastExcel.read(inputStream, excelHeaderClass, excelDataListener).sheet().doRead();
return Mono.just(ApiResponse.success());
} catch (IOException | ExcelModelNotFoundException e) {
return Mono.error(e);
}
});
}
But when I test it using command:
curl --location --request POST 'http://localhost:8080/path/to/import/excel' \
--header 'User-Agent: Apifox/1.0.0 ()' \
--header 'Accept: */*' \
--header 'Host: localhost:8080' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data; boundary=--------------------------675960818497163398905741' \
--form 'modelName="someName"' \
--form 'file=@"/path/to/file/upload-file.xlsx"'
It got error message like:
{
... omitted.
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' not supported for bodyType=.springframework.web.multipart.MultipartFile"
}
I have asked AIs for help but the approches given just didn't work at all.
P.S spring-webflux official doc .html doesn't tell much of what I should do in my scenario and it really has no necessity to save the uploaded file first for currently those files would be very small.
If anyone has idea about this question, I'd be thankful.
本文标签: javaReceiving files using Java23 and springwebfluxStack Overflow
版权声明:本文标题:java - Receiving files using Java23 and spring-webflux - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744761886a2623802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论