cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: RESTful file upload problem
Date Tue, 26 Mar 2013 13:11:56 GMT
Hi
On 26/03/13 15:53, srinivas thallapalli wrote:
> Hi,
>
>
> I have RESTful service for file upload as below
>
>
>      @POST
>      @Path("/fileupload")
>      @Consumes(MediaType.MULTIPART_FORM_DATA)
>      public void fileUpload(MultipartBody body) {
>          System.out.println("The API is called....");
>
>          try {
>            System.out.println("start post");
>            List<Attachment>  attachments = body.getAllAttachments();
>            DataHandler dataHandler = attachments.get(0).getDataHandler();
>            InputStream inputStream = dataHandler.getInputStream();

as a side note, you can simply do

InputStream is = attachments.get(0).get(InputStream.class)

>            OutputStream outputStream = new FileOutputStream(new
> File("C:/studentservice/new.pdf"));
>            IOUtils.copy(inputStream, outputStream);
>            inputStream.close();
>            outputStream.close();
>            System.out.println("end post");
>          } catch (Exception e) {
>            e.printStackTrace();
>          }
>      }
>
>
>
> I am trying to upload file from Apache HTTP client library as below
>
>
>   HttpClient httpClient = new DefaultHttpClient();
>          HttpPost httpPost = new
> HttpPost("http://localhost:8080/StudentService-RS/studentservice/fileupload");
>
>          FileBody fileBody = new FileBody(new File("C:\\test\\test.pdf"));
>
>          System.out.println(fileBody.getFilename());
>          MultipartEntity reqEntity = new MultipartEntity();
>          reqEntity.addPart("file1", fileBody);
>
>          httpPost.setEntity(reqEntity);
>
>          httpClient.execute(httpPost);
>
>
> But this client does not invoking the service. Am I missing something here?
>
I guess the path may not be matching ?
Cheers. Sergey
> Thanks
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/RESTful-file-upload-problem-tp5725256.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

Mime
View raw message