简体   繁体   English

无法使用Ruby的Framework Padrino读取上传的文件

[英]Can't read an uploaded file with Ruby's Framework Padrino

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. 顺便说一下,我正在Heroku上尝试此操作。 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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM