views:

591

answers:

3

I'm designing a RESTful API that should handle binary file uploads.
Should this be done the same way as html form upload or is there a better way?

+2  A: 

Theoretically you should do that with a "PUT" request. However this isn't supported by browsers. That leaves you with the plain html form upload as the only option.

kgiannakakis
Why PUT and not POST? POST (creating something new) seems more sensible; the file is just payload information.
S.Lott
@S.Lott - I agree POST can also be used for uploading - if the server chooses the new URI for the resource. See Restful Web Services (Richardson, L; Ruby, S) p.220.
Bedwyr Humphreys
+3  A: 

Take a look at the Amazon api for an idea. It uses a PUT query and then through sendREST it sends the content. Uploading files to Amazon S3 with REST API

Aggelos Mpimpoudis
A: 

A good way is to upload the binary information using streams. You could have a look at the JeCARS client project. To be exact the JC_RESTComm.java class performs the upload.

Waverick