Rails S3上传错误-IOError:关闭流

时间:2018-02-11 23:56:16

标签: ruby-on-rails amazon-s3

我有这段代码:

migrate

它正在抛出这个错误:

file = File.open(model_file_path, 'w') do |f|
  f << YAML.dump(attributes)
end

s3_bucket.object(filename).upload_file(file)

导致错误的原因是什么?我保存错了吗?

1 个答案:

答案 0 :(得分:0)

该文件需要处于打开状态才能上传:

file = File.open(model_file_path, 'w') do |f|
  f << YAML.dump(attributes)
end

File.open(model_file_path, 'r') do |f|
  s3_bucket.object(filename).upload_file(f)
end