1

I deployed an app in Heroku using Github, and the code works fine.

I have a piece of code which creates uploads directory in the root and puts in all uploaded files. I was able to retrieve the files without any trouble after uploading. However after an hour or so (perhaps after the dyno sleeps and restarts) the files were all gone.

A file (with a random file name) which was cached in git sneaked into the repository (although I have gitignored the directory) and not until I found the same exact file (with that exact name) on heroku server, I understood the problem is not that files are being deleted, but rather it's being synced with my repository that's causing the problem.

How do I prevent this from happening?

PS: I made sure Automatic deployment is off in heroku and checked again. Same results. Google doesn't give any relevant results for "files lost heroku" or "prevent automatic sync heroku github" ://

Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102

1 Answers1

1

Heroku uses an ephemeral filesystem. Local filesystem is only accessible to a single dyno, and once the dyno is stopped, restarted, or moved, all files on the local filesystem are destroyed.

In fact, I could not even see the uploads folder though heroku console even though I was able to download the file from the controller using send_file.

enter image description here

enter image description here

This also means that the files were lost not because the dyno synced with Github but because of the nature of the dynos and filesystem itself, that the dyno will not find the folder once restarted.

Credits: Benjamin Manns' Source: SO Answer

Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102