Search code examples
githeroku

After git push heroku - uploaded files on Heroku are lost


My fairly basic application allows users to upload avatars.

The application is deployed to Heroku with

$ git add .
$ git commit -m "description"
$ git checkout master
$ git merge my-cool-new-feature
$ git push heroku

The problem is, every time I push changes to Heroku, all files uploaded to Heroku are lost. I thought, the problem was that the folder/files were under version control, so I added the folder to .gitignore

# Ignore User generated files
/public/system/*

and removed the files from the repository.

$ git rm -rf --cached public/system

But the problem persists. Can you point me in the right direction?


Solution

  • The reason for this is because Heroku limits the way you can store data on their servers. Back in the bamboo stack days, storing any data was simply impossible without the use of an external service. Since they introduced the Cedar stack, things have changed a little bit, but storing persistent data is still not possible.

    As you've discovered, each time you push a new change to your Heroku application (or each time the application shuts down and restarts after being inactive for x minutes), your application is recreated and all stored data is lost.

    Your best bet is to not use the /public directory at all, and start using an external service like Amazon S3, Rackspace Cloud Files or Spideroak.