简体   繁体   中英

Heroku delete my uploaded files, why?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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