[英]Can't read an uploaded file with Ruby's Framework Padrino
我有此表格用于上传文件:
-# 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"
和这个控制器来处理它:
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
并且每次我尝试上传文件时,都会收到“内部服务器错误”。 我的日志有:
NoMethodError - undefined method `read' for #<Hash:0x00000003697780>:
顺便说一下,我正在Heroku上尝试此操作。 我不知道出了什么问题...似乎对很多人有用,但对我来说。
您应该使用:
file = params[:file][:tempfile]
我建议检索文件名
name = params[:file][:filename]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.