# File upload with REST POST?

**URL:** <https://www.ruby-forum.com/t/file-upload-with-rest-post/107546>\
**Category:** Rails\
**Created:** [June 22, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/file-upload-with-rest-post/107546 "2007-06-22T22:23:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 22, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/file-upload-with-rest-post/107546/1 "2007-06-22T22:23:36Z")

</div>

Does anyone know how I exactly I would post a file from a non-web  
client? In my case, I want to upload different file formats  
(.csv, .txt, etc) from the client’s file system. How does this work  
exactly if I’m not using a browser? What would be the format for  
the .REST POST?

I’m using a .NET client new to that and not sure exactly how to POST  
an external file from a non-web client through REST

Thanks  
Chirag

PS. I’m using attachment\_fu plugin which automatically creates a REST  
controller on the server side

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 23, 2007, 9:48pm UTC](https://www.ruby-forum.com/t/file-upload-with-rest-post/107546/2 "2007-06-23T21:48:41Z")

</div>

I don’t completely understand the “-F” switch

Is “password=@/etc/passwd” a path on the file system?

How would I send a .csv file in the same directory?

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 24, 2007, 10:04am UTC](https://www.ruby-forum.com/t/file-upload-with-rest-post/107546/3 "2007-06-24T10:04:33Z")

</div>

password is the field name and /etc/passwd is the file (on the file  
system) you want to upload.

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 23, 2007, 3:14am UTC](https://www.ruby-forum.com/t/file-upload-with-rest-post/107546/4 "2007-06-23T03:14:59Z")

</div>

You would send the file just like a browser would. Use a multi-part  
form with your file attached.

Here’s an example of sending a file with curl:

curl -F password=@/etc/passwd [www.mypasswords.com](http://www.mypasswords.com)

Notice the -F tells curl to use multipart/form-data according to  
RFC1867.

If curl can do it, I’m betting that .Net can too. 🙂

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [June 28, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/file-upload-with-rest-post/107546/5 "2007-06-28T17:44:51Z")

</div>

I tried the following comnmand  
curl -F “uploaded\_data=@curltest.docx”  
[http://localhost:3000/raw\_data\_files/create](http://localhost:3000/raw_data_files/create)

> results.html

and got the following errors from attachment\_fu (file upload) plugin

There were problems with the following fields:  
\* Content type can’t be blank  
\* Size is not included in the list  
\* Size can’t be blank  
\* Filename can’t be blank

Here’s my view which works fine on the upload (unlike cURL):  
\<%= error\_messages\_for :raw\_data\_file %\>

\<% form\_for(:raw\_data\_file, :url =\> raw\_data\_files\_path, :html =\>  
{ :multipart =\> true }) do |form| %\>

Upload a file: \<%= form.file\_field :uploaded\_data %\>

\<%= submit\_tag "Create" %\>

\<% end %\>

How do I manually set the filename, size, and content type in cURL?

Chirag
