0

Currently, Fine Uploader uses a POST to send the data to the server - is there a way to change this to a PUT in the options object? I'm using backbone.js, and a POST makes a new record, and a PUT triggers an update.

Thanks.

cajund
  • 141
  • 2
  • 11
  • Can you discuss you need for PUT vs POST a bit more? POST is appropriate for uploading a new file. Is there something else you are talking about? – Ray Nicholus Apr 26 '13 at 20:23
  • When using backbone.js. a POST signals to the server that the data being sent should be created as a new record. However, when updating a current record, backbone.js sends a PUT. The issues I am having is when I use Fine Uploader, it sends a POST, and that creates a new record each time as opposed to updating the record I am working with. I can probably work around this, but wanted to see if there was a way to send a PUT instead of a POST. Thanks. – cajund Apr 26 '13 at 20:53
  • I'm not sure I understand what you mean by "record". What "records" are you referring to? Assuming chunking is not enabled, Fine Uploader sends a POST request for each file to be uploaded. This is the appropriate method. Are you talking about chunked requests instead? – Ray Nicholus Apr 26 '13 at 21:02
  • Not talking about chunking. I'm talking about the type of request on the server. (http://stackoverflow.com/questions/630453/put-vs-post-in-rest) PUT or POST can be used, I wanted to change this method in Fine Uploader as the code on the server behaved differently when it received different types of requests. This is a backbone.js thing, so if you are not familiar, then this may be a bit difficult to explain here. Anyway, I've coded around it. Thanks. – cajund Apr 26 '13 at 22:57

1 Answers1

0

POST is the most appropriate method for an upload request, mostly because file upload requests are intended to be idempotent. PUT request are more appropriate for non-idempotent (update) requests.

However, there is another reason why PUT is not a good choice here: this will not work in IE9 and older. In those browsers, a form is submitted inside of a hidden iframe for each file to be uploaded, due to lack of File API support. There are only two valid values for the method attribute on a <form>: GET and POST. So you'd have to handle POST requests anyway, unless you are not going to support IE9 and older (not likely).

I am familiar with backbone.js, and there is no reason why POST requests cannot be used, especially in this instance. You haven't provided any specific reason why PUT requests are preferable here, so I can only assume that if there is such a requirement, this is likely due to some logic in your application that should probably be re-evaluated.

Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82