Heroku删除我上传的文件,为什么?

如果我在Heroku上的应用程序中加载文件,一切正常,但当我再次尝试重新加载应用程序时,它会给我以下错误:

2013-01-25T08:48:31+00:00 app[web.1]: app/controllers/main_controller.rb:20:in `index' 2013-01-25T08:48:31+00:00 app[web.1]: 2013-01-25T08:48:31+00:00 app[web.1]: 2013-01-25T08:48:31+00:00 app[web.1]: Errno::ENOENT (No such file or directory - /app/config/cases/casesID6.yml): 2013-01-25T08:48:31+00:00 app[web.1]: app/controllers/main_controller.rb:20:in `read' 

本地工作很精细!

主控制器:

 # importo yaml di configurazione require 'yaml' if Survey.exists?(1) @idOfSurvey = Survey.find {|s| s['active_state'] == true}['id'] nameOfSurvey = "casesID"+String(@idOfSurvey)+".yml" @survey = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config/cases', nameOfSurvey))).result) else render :action => 'noYaml' and return end 

上传控制器:

 #inserisco il nuovo questionario survey = Survey.new if Survey.exists?(1) n = String(Integer(Survey.maximum("Id"))+1) survey.name = "casesID#{n}" else survey.name = "casesID1" end File.open(Rails.root.join('config/cases', survey.name+".yml"), 'wb+') do |file| file.write(uploaded_io.read) end survey.save() 

我相信我上传到Heroku的文件可能会被平台清除,例如内存问题,或者因为它将它们保存为临时文件,这可能吗? 解决方案!

我再说一遍,一切都在当地很好:(

虽然您可以在扩展,重新启动或推送新版本的代码后写入Heroku文件系统,但文件将会消失。

您需要使用持久性文件存储,例如Amazon S3,Rackspace等 – 请阅读https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem上的更多内容,并使用像CarrierWave或Paperclip这样的gem连接到S3超级简单。