Hi, now that most modern browsers support the JavaScript File API, I wanted
to try to build a very simple file upload webapp with CXF/JAX-RS on the
backend and some simple jQuery stuff on the front-end.

I'm having a difficult time trying to get the web service declaration /
annotations working the way I want them.

Here's the simple use case on what I'm trying to do:

1) User will drag-n-drop a file off desktop into web page, we get a handle
to the file that can be used to submit
2) Client will POST to server as some variation of multipart/form-data,
multipart/mixed with two attachments:
    a) XML representation of JAXB class the server knows about which
contains file metadata
    b) The contents of the file itself

I've just been hacking (literally) on a simple demo project in
github...here's how the client posts the data:

https://github.com/davisford/kickstarter/blob/master/src/main/webapp/js/fileupload.js
-- see line 37 where I dynamically create a form and submit it

...the server method that receives it:

https://github.com/davisford/kickstarter/blob/master/src/main/java/com/example/fileupload/FileUploadServiceImpl.java
-- see line 67

The only way I've been able to sorta make this work is if the param to the
server method is MultipartBody, and then I have to go digging through the
API to find each piece.

I'd instead prefer it if I could somehow annotate / define the method to
figure this out for me (if possible)

For example, I'd like to have something like this...where the first param is
handled by JAXB (from XML to Java), and the second param is just an
InputStream to the attached file part contents.  I've tried a lot of
different variations here, but none of them are working -- for various
reasons (e.g. No message body reader found for request class :
FileUploadFile, ContentType : multipart/form-data.)  -- how can I get
CXF/JAXB to understand that one of the attachment parts should be
de-serialized into the FileUploadFile class, for instance?  I can do a GET
request and receive those back as XML just fine.

@Consumes(MediaType.MULTIPART_FORM_DATA)
public FileUploadFileResult create(

@Multipart(value="file-metadata", type=MediaType.APPLICATION_XML)
FileUploadFile file,
@Multipart(value="file-content",
type=MediaType.APPLICATION_OCTET_STREAM) InputStream istream) {
*
*
*
*

Reply via email to