Heroku删除我上传的文件,为什么? [英] Heroku delete my uploaded files, why?
问题描述
如果我在Heroku上的应用程序中加载文件,一切正常,但是当我再次尝试重新加载应用程序时,它会给我以下错误:
<$ p $ $ app_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(没有这样的文件或目录 - /app/config/cases/casesID6.yml):
2013-01-25T08:48:31 +00:00 app [web.1]:app / controllers / main_controller.rb:20:在`read'
本地工作精细!
主控制器:
#importo yaml di configurazione
要求'yaml'
如果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'并返回
结束
上传控制器:
#inserisco il nuovo questionario
survey = Survey.new
如果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的文件可能会被内存问题的平台清除,或者因为它将它们保存为临时文件,这可能吗?解决方案!
我再说一遍,一切正常的地方:($ / b>
一旦你缩放,重新启动或推送一个新版本的代码,你可以写入Heroku文件系统,然后文件就会消失。
您需要使用持久性文件存储,如Amazon S3,Rackspace等 - 阅读更多信息,请访问 https:// devcenter。 heroku.com/articles/dynos#ephemeral-filesystem ,并使用像CarrierWave或Paperclip这样的连接S3的超级简单。
if I load the file in my app on Heroku, everything works, but when I tried again to reload the application, it gives me the following error:
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'
LOCALLY IT WORK FINE !
main controller:
# 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
upload controller :
#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()
I believe that my file uploaded to Heroku, may be cleared by the platform for issues of memory, for example, or because it saves them as temporary, is this possible? solutions!
I repeat, everything works fine locally :(
Whilst you can write to the Heroku filesystem once you scale, restart or push a new version of your code then the file will be gone.
You need to use a persistant file store such as Amazon S3, Rackspace or such like - read more at https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem and use a gem like CarrierWave or Paperclip which make connecting to S3 super simple.
这篇关于Heroku删除我上传的文件,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!