Passing Files and String to REST service in Camel.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing Files and String to REST service in Camel.

Siddharth Patil
This post was updated on .
Hi,

I want to create a web service which accepts files(.png, .pdf, .txt) and
a String. Previously I created a service that accepts only files and the
structure of the service is as shown below :

@POST
@Path("/uploadDoc")
@Consumes("multipart/form-data")
@Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(final MultipartBody uploadedFile);

This is working fine.

Now I want a service that accepts String as well along with files. Here
is my HTML page layout through which I will be hitting the service :

<html>
<body>

JAX-RS Upload Form


<form
action="http://localhost:8080/IntegrationHub/hubServices/file/uploadDoc"
method="post" enctype="multipart/form-data">

<p>
Account Number : <input type="text" name="accountNumber">
</p>
<p>
Select a file : <input type="file" name="uploadedFile"/ multiple>
</p>

<input type="submit" value="Upload It" />
</form>

</body>
</html>


Please help.

Regards,
Siddharth Patil
Reply | Threaded
Open this post in threaded view
|

Re: Passing Files and String to REST service in Camel.

Sergey Beryozkin
Hi
MultipartBody is a container for multiple attachment parts - you can get
multiple parts from this object.
Alternatively you can have two method parameters instead:

@Multipart("name") String name
@Multipart("uploadedFile") InputStream file


or may be only

@Multipart("uploadedFile") Attachment att

and get the name from this Attachment's ContentDisposition header

Sergey


On 28/12/16 09:23, Siddharth Patil wrote:

> Hi,
>
> I want to create a web service which accepts files(.png, .pdf, .txt) and
> a String. Previously I created a service that accepts only files and the
> structure of the service is as shown below :
>
> @POST
> @Path("/uploadDoc")
> @Consumes("multipart/form-data")
> @Produces(MediaType.APPLICATION_JSON)
> public Response uploadFile(final MultipartBody uploadedFile);
>
> This is working fine.
>
> Now I want a service that accepts String as well along with files. Here
> is my HTML page layout through which I will be hitting the service :
>
> <html>
> <body>
> <h1>JAX-RS Upload Form</h1>
>
> <form
> action="http://localhost:8080/IntegrationHub/hubServices/file/uploadDoc"
> method="post" enctype="multipart/form-data">
>
> <p>
> Account Number : <input type="text" name="accountNumber">
> </p>
> <p>
> Select a file : <input type="file" name="uploadedFile"/ multiple>
> </p>
>
> <input type="submit" value="Upload It" />
> </form>
>
> </body>
> </html>
>
>
> Please help.
>
> Regards,
> Siddharth Patil
> Infrasoft Technologies Limited
> Tel: +91 20 6629 3416
> www.infrasofttech.com
>
> InfrasoftTech is a specialist solutions & services company for the
> Banking & Finance and Insurance Industry. We are a SEI CMMI Level 5 v1.3,
> ISO 9001 and ISO 27001 certified company having a global footprint with
> over 200 client banks and operations in United Kingdom, Channel Islands,
> U.S.A., Canada, India, Dubai, Singapore & Africa and a global Channel
> partner network in over 20 countries
>
> Notice:
> This correspondence may contain some privileged information. We cannot be
> held responsible in any manner for any misuse of this correspondence. If
> you are not the intended recipient of this email (including attachments
> if any) and have received the same in error, kindly delete the same,
> without retaining any copy in soft or printed form and inform the sender.
> ---------------------------------------------------------------------------------------
> This email has been scanned for email related threats and delivered
> safely by Mimecast.
> For more information please visit http://www.mimecast.com
> ---------------------------------------------------------------------------------------
>
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Passing-Files-and-String-to-REST-service-in-Camel-tp5791968.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Passing Files and String to REST service in Camel.

Siddharth Patil
Thank you Sergey Beryozkin. It works.