Рассмотрение требования к хорошему отдачу для передачи запроса, я решил использовать Spring-webflux в Springboot и кодирование в его реактивном виде.
Код: Выделить всё
@PostMapping(value = "/import/excel")
public Mono importExcel(@RequestPart("file") Mono 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);
}
});
}
< /code>
Но когда я тестирую его с помощью команды: < /p>
curl --location --request POST 'http://localhost:8080/path/to/import/excel' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--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"'
< /code>
Получил сообщение об ошибке, как: < /p>
{
... omitted.
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' not supported for bodyType=org.springframework.web.multipart.MultipartFile"
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ng-webflux