13

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?

4 Answers 4

28

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.

2
  • 1
    Thanks for the answer. Since the database content stays, I already ruled the reset out. And I could not find anything about that in Herokus "Getting started"-documents. One might think that developers would like that info the FAQs. Thanks again! Commented Jun 28, 2012 at 14:33
  • 3
    Well, database and file access are two different things. Heroku has to support some kind of persistent storage or it would be totally useless for developers to quickly launch a functional app, so they give you access to a shared postgreSQL instance, but that does not include file storage access.
    – JeanMertz
    Commented Jun 28, 2012 at 14:36
2

If your application needs to receive files uploaded by users, you need to make sure these uploads are stored in a central and durable location.

With Heroku’s ephemeral filesystem, any information written to a dyno’s filesystem will be lost when the dyno is restarted. Instead, Heroku recommends backing services. For file and media storage, Amazon’s Simple Storage Service (S3) is a great solution.

You might want to read this arcticle on Heroku website: Uploading Files to S3 in Ruby with Paperclip

1
1

Your files will be lost with every deployment. My preferred solution is using Paperclip and an Amazon bucket. Paperclip will store your image in the bucket so it can be referenced at will from the app.

0

just change your mongodb network access to "anyone access" problem solved.

all above steps i did but does not work then finally i change monodb access and it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.