Thanks.

1) If I use cxf WebClient, I can set contentId like the follwing:

attachmentList.add(new Attachment("pdf1", "application/pdf", new 
FileInputStream(uploadFile)));

If I use the the following form to upload the file, How can I contentId?
 
 <form method="post" action="/spring_cxf_rest/rest/upload/book" 
enctype="multipart/form-data">
  name: <input type="text" name="name"/><br/>
  file: <input type="file" name="file"/><br/>
  <input type="submit" value="Submit"/>
 </form>

2) According to cxf guide "When handling complex multipart/form-data 
submissions (such as those containing files) MultipartBody (and Attachment) 
need to be used directly."

When I handle the above form, I have to use MultipartBody, is there easy way to 
parse text input and file input from MultipartBody?

Regards.


--- On Thu, 2/3/11, Sergey Beryozkin <[email protected]> wrote:

> From: Sergey Beryozkin <[email protected]>
> Subject: Re: some questions about cxf rest uploading file
> To: [email protected]
> Received: Thursday, February 3, 2011, 9:54 AM
> Hi
> 
> On Thu, Feb 3, 2011 at 2:29 PM, acec acec <[email protected]>
> wrote:
> 
> > 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?
> >
> > Content-Id the id of the individual multi-part; sure,
> if you know the
> contentId then you can use
> 
> body.getAttachment(contentId)
> 
> 
> > 2)Can I get original file name on server side? I
> tried
> > dataHandler.getName(), but it return null.
> >
> >
> If it's a multipart/form-data then you can get a
> ContentDisposition header
> from the Attachment and get the name; otherwise you can
> just introduce a
> custom header and use it during the creation of the
> individual part and then
> retrieve it from Attachment.
> 
> 
> > 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?
> >
> > You're using the the Apache Http Client, so I'm not
> sure what exactly it
> produces. If it's a multipart/form-data request then on the
> cxf side do
> attachment.getContentDisposition() and get the file name
> 
> 
> > 4)I never use MTOM, when I am using the following code
> to upload one PDF
> > file, does is use base64?
> >
> >
> Not sure what Apache HttpClient does there
> 
> Cheers, Sergey
> 
> 
> > 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