Code: Select all
@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>
Aber wenn ich es mit dem Befehl teste: < /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>
Es wurde Fehlermeldung wie: < /p>
erhalten{
... 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"
}
Wenn jemand eine Vorstellung zu dieser Frage hat, wäre ich dankbar.