Hello Federico,

Go below error when platform http component used.





Thank
Karthik



On Wed, 14 May 2025, 2:49 pm Federico Mariani, <
federico.mariani.1...@gmail.com> wrote:

> Hello,
>
> Lately, we did a lot of improvements to the platform-http component. Can
> you try using the latest Camel 4.10.x release and platform-http instead of
> servlet? IIRC, in platform-http component the attachments are handled in
> the body (if only one attachment is present) and the message attachments.
>
> Il giorno mer 14 mag 2025 alle ore 07:59 KARTHIK PRABHU N <
> karthikprabh...@gmail.com> ha scritto:
>
> > Hello Team,
> >
> > Good morning !
> >
> > I have a route exposed as REST endpoint with method POST which should
> > extract attachment file from the request but somehow, it’s not working.
> But
> > the same route - of course with different logic – able to extract
> > attachment from the body. Could you please explain this behavior.? You
> can
> > find more information below.
> >
> > Camel version : 4.8.03
> >
> >
> >
> > curl --location 'http://0.0.0.0:8888/camel/upload' \
> >
> > --header 'Content-Type: multipart/form-data' \
> >
> > --form 'filename=@"/C:/Users/karthik/Downloads/agv_2025032716202293.xml"'
> >
> >
> >
> >
> >
> > *Endpoints are exposed using REST DSL with Servlet component. *
> >
> >
> >
> > restConfiguration()
> >         .component("servlet")  // Use Servlet (important for Spring Boot)
> >         .bindingMode(RestBindingMode.*off*) // Ensures JSON response
> >         .contextPath("/")  // Base API Path
> >         .apiContextPath("/api-doc")  // OpenAPI spec available at
> /api-doc
> >         .apiProperty   ("api.title"        *,*"example project")
> >         .apiProperty   ("api.version"      *,*gitCommitId)
> >         .componentProperty("responseBufferSize"*,*
> > "100000").endpointProperty("attachmentMultipartBinding"*, *"true")*;*
> >
> >
> >
> > *Route *
> >
> >
> >
> > From(rest:post:floorplan/upload?consumes=multipart/form-data)
> >
> > .process(exchange -> {
> >                         Message message = exchange.getMessage();
> >
> >                         AttachmentMessage in =
> > exchange.getIn(AttachmentMessage.class);
> >
> >                             System.out.println("has attachments" +
> > in.getAttachments().size());
> >
> >
> >
> > })
> >
> >
> >
> >
> >
> > *But the below logic works, here I am not sure how attachment is read
> from
> > the message body which is ideal should be present in the message
> > attachment. *
> >
> >
> >
> > try( InputStream bis = new
> >
> >
> BufferedInputStream(exchange.getMessage().getMandatoryBody(InputStream.class));
> > BufferedOutputStream bos = new BufferedOutputStream(new
> > FileOutputStream("upload/abc.bin"));){
> > int bytesRead = bis.read();
> > while (bytesRead != -1){
> >     bos.write(bytesRead);
> >     bytesRead = bis.read();
> >
> > }
> >
> >
> >
> > Best regards,
> >
> > *Karthik Prabhu N*
> > ​
> >
>

Reply via email to