views:

13

answers:

1

Hi all

I have to make a web call which will take a file from the user and post it to the server. i am new to web so what should mt url be like.

i tried http//www.example.com?param[id]=1

so what should the next parameter be which will take uploaded file data.

i think he has to give me the binary data of the file

thanks in advance

A: 

You need to make a simple multi-part form using the form_tag helper:

<% form_tag(examples_path, :method => :post, :multi_part => true) do %>
  <%= file_field_tag(:file) %>
  <%= submit_tag('Upload') %>
<% end %>

You can't submit files by a GET request. It must be POST, and it must be set multi-part.

tadman
@tadman hey thanks for the help.can we post file without the form something like appending binary data to the url
dln
You can't post `<file>` fields to a GET request, it's simply not allowed. URLs are also typically limited to about ~1500 bytes. The only way to send a file by a GET request is to have uploaded it somewhere else first and send a reference to that location.
tadman
@tadman hey can i send binary data in POST method
dln
Yes, which is why I answered the question with an example.
tadman