3

I'm trying to use REST Client for Firefox as a mock form to post multipart file data to a Spring 3-driven controller and subsequent handlers. I have our Web Services project configured such that we are able to send XML/JSON requests, which are marshaled/unmarshaled and consumed in the usual way. When I try to use the enctype="multipart/form-data" (by sending the Content-Type="multipart/form-data"), I immediately get :

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

I've been sure to include this in my rest-servlet configuration :

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="100000"/>
</bean>

Thinking that this was a limitation of the commons FileUpload jar version, I tried to older releases, but to no avail. Same with my REST Client, trying both this and this

My ultimate goal would be to have JAXB marshal a specified file into an object that contains a byte[] automatically. For a great reference as to what I'd like to see, this post hits exactly that, but it uses RESTEasy as the implementation, whereas I use Spring 3 (and this cannot be changed).

Ideally, POSTing this XML :

<fileUpload>
    <username>user123</username>
    <localFileToBeUploaded>path/to/file</localFileToBeUploaded>
</fileUpload>

Would result in an FileUpload object containing the username as a String and the file as either a byte array, InputStream, or actual File object, which gets mapped to some specific controller for handling. I'm comfortable with the XML marshaling, but I'm lost as to how to deal with the file aspect.

Is this possible or am I mixing two different paradigms? I haven't been able to come across anything like this, which leads me to believe I'm a little out in left field. Any ideas or comments would be hugely helpful. Thank you!

Community
  • 1
  • 1
Nick
  • 31
  • 1
  • 1
  • 2
  • 2
    I've solved the multipart boundary exception after reading [this blog post](http://renatoc.wait4.org/2011/02/25/posting-multipartform-data-using-apache-wink/). To anyone having this problem, in the REST Client, when specifying the Request Header, use **"Content-Type" as the Name** and **"multipart/form-data; boundary=xyzxyz" as the Value**. I'm still struggling with getting the file (or any value, really) to bind to the Model attributes, however. – Nick Jan 24 '12 at 17:25

1 Answers1

2

This will be available in REST Client 3.1 it looks like: http://code.google.com/p/rest-client/issues/detail?id=100

jediwompa
  • 21
  • 2