You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by jamalissimo <ro...@gmail.com> on 2013/07/10 16:11:47 UTC
Multipart file upload
Hello guys,
I am working on file upload via CXF and I have little problem.
Here is the REST part:
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/upload")
@Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(
@Multipart("document") byte[] document,
@Multipart("product") String product,
@Multipart("uploader") String uploader,
@Multipart("folderId") String folderId)
throws IOException {
return null;
}
Problem is, that I need somehow to get the name of the file, but I am not
sure if it is possible from byte[].
I am using Karaf 2.3.1
Thanks for help
-Roman
-----
-Br, Roman
--
View this message in context: http://cxf.547215.n5.nabble.com/Multipart-file-upload-tp5730547.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Multipart file upload
Posted by Christopher Riley <cr...@hkmconsultingllc.com>.
Hi Roman,
I have used the following in some of the code I have in JAX-RS:
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail
you can then use fileDetail.getFileName();
Chris
On Wed, Jul 10, 2013 at 10:11 AM, jamalissimo <ro...@gmail.com>wrote:
> Hello guys,
>
> I am working on file upload via CXF and I have little problem.
> Here is the REST part:
>
> @POST
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @Path("/upload")
> @Produces(MediaType.APPLICATION_JSON)
> public Response uploadFile(
> @Multipart("document") byte[] document,
> @Multipart("product") String product,
> @Multipart("uploader") String uploader,
> @Multipart("folderId") String folderId)
> throws IOException {
>
> return null;
> }
>
> Problem is, that I need somehow to get the name of the file, but I am not
> sure if it is possible from byte[].
> I am using Karaf 2.3.1
>
> Thanks for help
>
> -Roman
>
>
>
> -----
> -Br, Roman
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Multipart-file-upload-tp5730547.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Chris Riley, Partner
HKM Consulting LLC
(w) hkmconsultingllc.com
(o) 774.553.5314
(m) 508.273.3102
(f) 774.553.5316
Re: Multipart file upload
Posted by jamalissimo <ro...@gmail.com>.
One more hint to file upload. Even I had encoding set to UTF-8, headers were
still in ISO-8859-1. So when I needed to send file which contained special
characters in the name I got only hieroglyphs :-)
To convert file name to UTF-8 I used this:
Attachment att = exchange.getIn().getBody(Attachment.class);
String filename = new
String(att.getDataHandler().getName().getBytes("ISO-8859-1"), "UTF-8");
-Roman
-----
-Br, Roman
--
View this message in context: http://cxf.547215.n5.nabble.com/Multipart-file-upload-tp5730547p5731080.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Multipart file upload
Posted by jamalissimo <ro...@gmail.com>.
Hello guys,
thanks for help. I finally made it working:
REST part:
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/upload")
@Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(
@Multipart(value = "document") @NotNull Attachment attachment,
@Multipart("product") String product,
@Multipart("uploader") String uploader,
@Multipart("folderId") String folderId) {
return null;
}
This the way I can access all neccessary information:
Attachment att = exchange.getIn().getBody(Attachment.class);
System.out.println("Disposition = " + att.getContentDisposition());
System.out.println("Headers" + att.getHeaders());
System.out.println("File name" + att.getDataHandler().getName());
Hope it will help somebody :-)
-----
-Br, Roman
--
View this message in context: http://cxf.547215.n5.nabble.com/Multipart-file-upload-tp5730547p5730583.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Multipart file upload
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 10/07/13 15:11, jamalissimo wrote:
> Hello guys,
>
> I am working on file upload via CXF and I have little problem.
> Here is the REST part:
>
> @POST
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @Path("/upload")
> @Produces(MediaType.APPLICATION_JSON)
> public Response uploadFile(
> @Multipart("document") byte[] document,
> @Multipart("product") String product,
> @Multipart("uploader") String uploader,
> @Multipart("folderId") String folderId)
> throws IOException {
>
> return null;
> }
>
> Problem is, that I need somehow to get the name of the file, but I am not
> sure if it is possible from byte[].
use 'org.apache.cxf.jaxrs.ext.multipart.Attachment' data type instead of
byte[], you can check headers like Content-Disposition, and then do
attachment.getObject(InputStream.class)
Cheers, Sergey
> I am using Karaf 2.3.1
>
> Thanks for help
>
> -Roman
>
>
>
> -----
> -Br, Roman
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Multipart-file-upload-tp5730547.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com