简体   繁体   中英

Why do dynamic images I uploaded using Django admin on a Heroku deployment not showing up?

I have an e-commerce Django website hosted in Heroku (free acc). I dynamically upload the image and price through the Django admin page. The images were showing up for one day, but from the next day, I am getting an "image not found (404)" error. What's the reason for this error?

Failed to load resource: the server responded with a status of 404 (Not Found)

You can't save (persistantly) media files into Heroku's local filesystem.

The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container based systems, such as Docker, operate.

In addition, under normal operations dynos will restart every day in a process known as "Cycling" .

These two facts mean that the filesystem on Heroku is not suitable for persistent storage of data. In cases where you need to store data we recommend using a database addon such as Postgres (for data) or a dedicated file storage service such as AWS S3 (for static files). If you don't want to set up an account with AWS to create an S3 bucket we also have addons here that handle storage and processing of static assets https://elements.heroku.com/addons

Reference: https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM