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 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
read the manual (api.rubyonrails.org) and perhaps try this:
in your view:
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)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs