Uploading files with Restful interface

I'm trying to upload a file (like image file) into a Restful server like this:

curl -X POST -H "Content-Type: multipart/form-data; boundary=----------------------------4ebf00fbcf09" --data-binary @sample.jpg http://localhost:3000/test

However, the request doesn't seem to be processed by my Restful server resource.

  • How to upload a file (small and large ) to a Spring web resource
  • Is the "attachment" type upload is totally different than uploading through a simple Form upload?
  • If the Content-Type: multipart/form-data; boundary=... how can I get the actual content type, like: "image/jpeg" etc.

This is the code snippet for my web resource:

            ServletFileUpload upload = new ServletFileUpload();
            FileItemIterator fileIterator = upload.getItemIterator(req);
            while (fileIterator.hasNext()) {
                FileItemStream item = fileIterator.next();
                byte[] content = ByteStreams.toByteArray(item.openStream());

My concern is the type of client-side upload that the code can support, I use Rest Console Chrome plugin and upload attachment which works with this code, but the cURL code above is not working.

Also, what are the possible FileItemIterators that can be retrieved from a HttpServletRequest?

Here is the complete code of my restful web service resource: http://bit.ly/QwTOLw


You might want to take a look at the Spring manual's section on Spring's multipart (file upload) support. Make sure you have a MultipartResolver bean declared in your context and consider mapping the file as a MultipartFile in a form-backing object so you can have Spring handle resolving/reading the multipart data itself (rather than trying to parse the FileItemIterator, ServletFileUpload etc yourself).

Need Your Help

Custom Baseclass for WPF-Control

c# .net wpf visual-studio xaml

I've created a CustomControl for my Project and I'm going to create some more. All these Controls will have something in common, so i created an abstract class which inherits from UserControl.

Array merge if key not exists

php arrays

I tried merging two arrays if the key is not exists in the array but I cannot accomplish this. How can i do? This is what I have tried:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.