Return to Snippet

Revision: 29281
at July 24, 2010 21:12 by almazom


Updated Code
post '/upload' do
    unless params[:file] &&
           (tmpfile = params[:file][:tempfile]) &&
           (name = params[:file][:filename])
      @error = "No file selected"
      return haml(:upload)
    end
      directory = "public/files"
      path = File.join(directory, name)
      File.open(path, "wb") { |f| f.write(tmpfile.read) }
end

----------------
%form{:action=>"/upload",:method=>"post",:enctype=>"multipart/form-data"}
  %input{:type=>"file",:name=>"file"}
  %input{:type=>"submit",:value=>"Upload"}

Revision: 29280
at July 24, 2010 21:12 by almazom


Initial Code
post '/upload' do
    unless params[:file] &&
           (tmpfile = params[:file][:tempfile]) &&
           (name = params[:file][:filename])
      @error = "No file selected"
      return haml(:upload)
    end
      directory = "public/files"
      path = File.join(directory, name)
      File.open(path, "wb") { |f| f.write(tmpfile.read) }
end

----------------
%form{:action=>"/upload",:method=>"post",:enctype=>"multipart/form-data"}

	%input{:type=>"file",:name=>"file"}

	%input{:type=>"submit",:value=>"Upload"}

Initial URL

                                

Initial Description

                                

Initial Title
sinatra.rb upload image

Initial Tags
image, ruby

Initial Language
Rails