How to upload or download a file using ror

Hi friends,

    i am a fresher to ruby on rails . i need sample code/program

of how to download or upload files,and i also want code to stage a
file instead of posting it to a webserver.

i would be thankful if u can give me this information

Sathyanarayana Swamy wrote:

Hi friends,

    i am a fresher to ruby on rails . i need sample code/program

of how to download or upload files,and i also want code to stage a
file instead of posting it to a webserver.

i would be thankful if u can give me this information

Hi,

This works for Uploading File.

In Controller:

def uploadFile
if(@params[‘commit’] ==“Upload”)
path=“C:\Intranet\directory\public\data\file”
File.open(path,“wb”) {|f|
f.write(@params[:upload][:datafile].read)}
render :text =>“File has been uploaded successfully”
end
end

In rhtml

<%= start_form_tag ({:action => ‘uploadFile’}, :multipart => true) %>
Select File :
<%= file_field ‘upload’, ‘datafile’ %>
<%= submit_tag “Upload” %>
<%= end_form_tag %>

Archana

Uploads:

http://uploadcolumn.rubyforge.org/

Downloads: ( send_file )

read the manual (api.rubyonrails.org) and perhaps try this:

in your view:

Fileupload <%= start_form_tag({:action => 'upload_file'}, :multipart => true) %> <%= file_field_tag("uploaded_file")%> <%= submit_tag('Save')%> <%= end_form_tag %>

in the controller:

def upload_file
file_content = “”
file_io = params[:uploaded_file]
file_io.each_line {|line|
}
render :text => “duh…”

end

Sathyanarayana Swamy wrote:

Hi friends,

    i am a fresher to ruby on rails . i need sample code/program

of how to download or upload files,and i also want code to stage a
file instead of posting it to a webserver.

i would be thankful if u can give me this information

For Downloading use Send_file

In controller,

send_file(@path,
:filename => params[:filename] ,
:type => ‘application/octet-stream’,
:disposition => “attachment”,
:streaming => true,
:buffer_size => 4096)