Still trying to get multipart/form-data upload to work with a Resteasy
client ...

After some experimenting, I now found out that you can add an
@PartType annotation to the client's Map parameter, like this:

Object doUpload(@PartType(MediaType.APPLICATION_OCTET_STREAM)
Map<String, DataSource> parts);

And then use this as:

Map<String, DataSource> parts = new HashMap<String, DataSource>();
parts.put("file", new FileDataSource(new File("mypic.jpg")));
Object response = client.doUpload(parts);

Resteasy will then use

That way, however, two important things are missing from the HTTP
request (compared to a direct upload from a browser): the Content-Type
is hard-wired to application/octet-stream because of the annotation
and the mime part containing the file data does not have a
Content-Disposition header with a "filename" parameter with the
DataSource's name (in this example, this should be
Content-Disposition: attachment; filename="mypic.jpg").

Might this get fixed or do you suggest coding the upload with a
hand-crafted request?


> Hi,
> how do I parameterize an interface method for a POST call that
> consumes a multipart/form-data, for use with use
> org.jboss.resteasy.client.ProxyFactory?
> The server implements something like this:
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @Produces(MediaType.APPLICATION_JSON)
> @Path("wherever")
> public Response doFooImpl(MultipartFormDataInput object) {
> List<InputPart> items = object.getFormDataMap().get("ITEM"); /* ... */
>  }
> In the client, I tried this:
> @Consumes(MediaType.MULTIPART_FORM_DATA)
> @Produces(MediaType.APPLICATION_JSON)
> @Path("wherever")
> Object doFoo(Map<String, DataSource> parts);
> But when I run this, the client throws a
> java.lang.RuntimeException: could not find writer for content-type
> multipart/form-data type: java.util.Map
> Would it be better to use a javax.mail.Multipart as a client-side
> parameter? Or 
> org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInputImpl
> (if that is an "official" API class)?
> Thanks, Jay

All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
Resteasy-users mailing list

Reply via email to