Hi, all
I am using the following code to upload a file. It works fine.

But I have several questions:
1) If I change body.getAllAttachments() ==> body.getAttachment(contentId),
What does mean "contentId"? In my junit code, How can I set that contentId?

2)Can I get original file name on server side? I tried dataHandler.getName(), 
but it return null.

3)In my junit code, when I add Part using (reqEntity.addPart("file1", 
fileBody)), how can I retrieve the name "file1" from my server side?

4)I never use MTOM, when I am using the following code to upload one PDF file, 
does is use base64?

Thanks a lot.

===============Server side coe===============================
@POST
@Path("/upload/book")
public void postBook(MultipartBody body) {
 try {
  System.out.println("start post");
  List<Attachment> attachments = body.getAllAttachments();
  DataHandler dataHandler = attachments.get(0).getDataHandler();
  InputStream inputStream = dataHandler.getInputStream();
  OutputStream outputStream = new FileOutputStream(new File("/tmp/new.pdf"));
  IOUtils.copy(inputStream, outputStream);
  inputStream.close();
  outputStream.close();
  System.out.println("end post");
} catch (Exception e) {
  System.out.println("Exception");
}
}

====================My Junit==========================
public class UploadClassTest {
  @Test
  public void uploadClass() throws ClientProtocolException, IOException {
   HttpClient httpClient = new DefaultHttpClient();
   HttpPost httpPost = new 
HttpPost("http://localhost:8080/spring_cxf_rest/rest/upload/book";);

   FileBody fileBody = new FileBody(new File("/tmp/Citi.pdf"));

   MultipartEntity reqEntity = new MultipartEntity();
   reqEntity.addPart("file1", fileBody);

   httpPost.setEntity(reqEntity);

   httpClient.execute(httpPost);
 }
}


Reply via email to