简体   繁体   English

文件上传杀死了Rails应用程序和服务器

[英]File upload kills rails app and server

I have simple model which looks like this: 我有一个简单的模型,看起来像这样:

def video_file=(input_data)
  unless input_data.to_s.empty?
    newfile = File.open("#{RAILS_ROOT}/public/to_upload/#{self.filename}_vid.f4v", "wb") do |f|
      while buff = input_data.read(4096)
        f.write(buff)
      end
    end
  end
end

and here the error which rails manages to display and then dies, literally. 实际上,这是rails设法显示然后消失的错误。

 ActiveRecord::StatementInvalid in <ControllerName>

Why? 为什么?

Replace 更换

newfile = File.open(path, "wb") do |f|
while buff = input_data.read(4096)
  f.write(buff)
end

with

if input_data.respond_to?(:read)
  File.open(path, "wb") { |f| f.write(input_data.read) }
end

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

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