I have this form for uploading files:
-# coding: utf-8
- content_for(:body_classes, "body3")
.content
- form_tag url(:images, :create), :method => :post, :multipart => true do
= file_field_tag :file
= submit_tag "Upload"
And this Controller to handle it:
Fbapp.controllers :images do
get :new do
render 'images/new'
end
post :create do
require 'net/ftp'
file = params[:file]
ftp = Net::FTP.new('xxx.xxx.xxx.xxx')
ftp.passive = true
ftp.login('user','pass')
ftp.storbinary("STOR " + "original_filename", StringIO.new(file.read), Net::FTP::DEFAULT_BLOCKSIZE)
ftp.quit
end
end
And every time I try to upload a file I get "Internal Server Error". And my log has this:
NoMethodError - undefined method `read' for #<Hash:0x00000003697780>:
I'm trying this on Heroku by the way. I can't figure out what's the problem... It seems to work for a lot of people but me.
You should use:
file = params[:file][:tempfile]
and I suggest to retrieve the filename
name = params[:file][:filename]