0

I want to send a file in a REST PUT request. The user should be able to choose the file he wants to load from his local machine. I need to load the file as binary content and send it as part of the PUT request.

How can i let the user choose the file and load its binary content?

Erik Sapir
  • 23,209
  • 28
  • 81
  • 141

1 Answers1

0

You should have a form with the enctype of multipart/form-data and the method equals PUT

<form method="PUT" enctype="multipart/form-data" action="http://myrestserver.com/">

User name: <input type="text" name="username" />
<br />
Password: <input type="password" name="password" />
<br />
File to upload: <input type="file" name="uploaded_file">
<br />
<input type="submit" value="Press"> to upload the file!

</form>
Felipe Sabino
  • 17,825
  • 6
  • 78
  • 112
  • I don't have all the data in the form. there are more parameters i should put on the request, including username and password – Erik Sapir May 15 '11 at 15:02
  • You can add as much data as you want as hidden fields - `` - Although anything related to username and password should be handled by the server side for security reasons. – Felipe Sabino May 15 '11 at 15:45
  • the user name and pass are inserted by the user, and are unknown. What i need is to be able to read the file as binary data to a local var (should work also in FF and IE) – Erik Sapir May 15 '11 at 16:26
  • So, that is it. the user name and the password are going to be text inputs. simple like that. I will edit the question with the inputs – Felipe Sabino May 15 '11 at 17:11
  • I receive the login info earlier in other place. I want to send the file using Webdav protocol. what i need is the binary data of the file. – Erik Sapir May 15 '11 at 18:17
  • have you tried the webdav plugin for query? http://plugins.jquery.com/project/WebDAV – Felipe Sabino May 15 '11 at 22:36
  • you can try something similar to what I've answered here: http://stackoverflow.com/questions/1601455/check-file-input-size-with-jquery/3937404#3937404 But, as browsers security policies can not be overriden by JS, the access to file system information might not work with some browsers, like IE – Felipe Sabino May 16 '11 at 13:08