How to serve Python's Media files on heroku

So i've read the documentations and the solution to this is not included. I've posted this same Question on Quora pending an answer so i decided to ask on here. My project has features that allows users to upload their profile picture and also make contents that include images like posting thier pictures. All conditions passes the tescases from the project and no issue seems to be detected but it won't shows media files when hosted on heroku . From the python file, i'm uploading media files to another media variable in the database, for example image = database.ImageField( upload_to="media") and media URLS is defined as MEDIA_ROOT = "/media/" MEDIA_URL = os.path.join(os.getcwd(), "media") The HTML form submitting the media files is written as <form method="post" enctype="multipart/form-data"> ........... </form> But still, media files won't show up when uploaded on Another server. A Suggestion would be better but i won't show my backend codes

11/17/2019 7:13:51 PM

Mirielle🐶 [Inactive]

4 Answers

New Answer


I'm not sure that you can upload images or say any static assets directly on heroku. Maybe using another storage like Amazon S3 might be of help. Edit: I found a kind of similar question here https://stackoverflow.com/questions/24642967/can-i-host-images-in-heroku-or-do-i-need-s3 Read the first answer and check the link given at its bottom. This should be helpful Edit++: Also, one other answer reads: "If I'm not mistaken, Heroku doesn't allow writes on its filesystem, so, you would not be able to upload a file to your application at Heroku. That's why they suggest you to use and integrate Amazon S3 as a storage option."


Glad it worked! 😁👍 Btw what did you change media root exactly to?


After uploading the files to S3.. The media URL changed to that of S3 so i need to reconfigure that and delete the line that says "os.path.join(....)" Since the media is no more on my local disk


Yes, it works but i had to change the media root after