Using Apache-Camel ESB, trying to upload a xlsx file to Spring Rest Web application. Upload fails from apache-camel ESB. But upload works fine from Postman. Shared code snip
You can probably see this error message in your Spring backend log:
org.springframework.web.multipart.MultipartException: Current request is not a multipart request.
You need to set correct ContentType
header. Please refer this similar question for solution, if you want to implement it in this way.
But you can get out this mess, if you switch co camel-http4
component (you already have this component in pom.xml). This component contains logic for converting HttpEntity
to InputStream
. Then you can set HttpEntity
directly to exchange body.
Then your route will look something like this:
from("file://data/PASInput").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
File file = exchange.getIn().getBody(File.class);
multipartEntityBuilder.addPart("file",
new FileBody(file, ContentType.MULTIPART_FORM_DATA, filename));
exchange.getOut().setBody(multipartEntityBuilder.build());
}
}).to("http4://localhost:8080/Pastel/api/convertor/pas/pastel")
.log(LoggingLevel.ERROR, "RESPONSE BODY ${body}").end();
And just a note. Never mix component versions, always use for components the same version as Apache Camel version. Otherwise you can see upredictable results. And why you have annotation @ResponseBody
in Spring controller, when the method is void
? You don`t need that.