Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After git push heroku - uploaded files on Heroku are lost

Tags:

git

heroku

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?

like image 740
Valentin Klinghammer Avatar asked Jun 28 '12 14:06

Valentin Klinghammer


People also ask

Why are my file uploads missing deleted Heroku?

Heroku does not support file uploads. The filesystem is readonly. You'll have to host your uploaded files somewhere else (or from the database, which is a bad option). If you are using any gems like paperclip or carrierwave for uploading, using S3 will be simple.

How do I recover my Heroku files?

Log onto your heroku instance using heroku run bash. Use base64 to print the contents of your file: base64 <your-file> Select the base64 text in your terminal and copy it. On your local machine decompress this text using base64 straight into a new file (on a mac I'd do pbpaste | base64 --decode -o <your-file> )

Where does Heroku store uploaded files?

Files are uploaded directly to the cloud from your user's browser, without passing through your application. Adding direct uploads to your app allows you to offload the storage of static files from your app. This is crucial on Heroku, because your app's dynos have an ephemeral filesystem.

Does Heroku provide file storage?

Heroku has an “ephemeral” hard drive, this means that you can write files to disk, but those files will not persist after the application is restarted. By default Active Storage uses a :local storage option, which uses the local file system to store any uploaded files.


1 Answers

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.

like image 150
JeanMertz Avatar answered Oct 18 '22 21:10

JeanMertz