soveran / cuba

Rum based microframework for web development.
http://cuba.is
MIT License
1.44k stars 249 forks source link

wrong number of arguments (given 0, expected 1..2) when upload file #99

Closed tablecell closed 4 years ago

tablecell commented 4 years ago
  on get do
    on 'upload' do 
        res.write '<form action="/multipart" enctype="multipart/form-data" method="post" ><input name="file" type="file" /><input type="submit" value="upload" /></form>'

    end
 end 
  on post do 

    on 'multipart' do 

                 tmpfile =  param["file"][:tempfile]
        filename =  param["file"][:filename]
        target="public/upload/#{filename}"
        File.open(target,'wb') {
        |f| f.write(tmpfile.read) 
        }

    end
end
soveran commented 4 years ago

@tablecell The method param has a different meaning in Cuba. Try req instead of param, as in the following example:

tmpfile = req["file"][:tempfile]
filename = req["file"][:filename]

Let me know how it goes.

tablecell commented 4 years ago

req works right