[Django]-OSError: [Errno 30] Read-only file system in Django on Heroku

5👍

Changed MEDIA_ROOT path by removing additional os.path.dirname() and it is working now.

MEDIA_ROOT = os.path.join(BASE_DIR, 'static_cdn', 'media_root')

6👍

In my case, this error occurred because I set the STATIC_ROOT = '/static/'

This means it’s looking at / root folder of the system and then static, which is obviously read-only,

changing it to STATIC_ROOT = 'static/' fixed my issue.

1👍

I’m using gTTS to convert text to speech and save .mp3 file in the media directory

I’m not sure what’s causing your immediate error, but this isn’t going to work very well on Heroku. Its filesystem is ephemeral: you can write to it, but whatever you write will be lost when the dyno restarts. This happens frequently (at least once per day).

Heroku recommends using a third-party file or object store like Amazon S3 for storing generated files, uploaded files, etc. I recommend gong down this path. There are many Django libraries for using S3, and other services, as storage backends.

👤Chris

Leave a comment