404 not found when requesting image url

i need to upload an image to my endpoint and get this image as a url like https://er.onrender.com/media/accounts/images/2024/07/07/15/55/29/IMG-20231213-WA0002.jpg) , what happened is : i post the image and i get the url and i can open it , but the url works for limited time and when i open it again i find 404 ( “/opt/render/project/src/media/accounts/images/2024/07/07/15/55/29/IMG-20231213-WA0002.jpg” does not exist)

Request Method: GET

i do not no the reason ,
here is the related code for this static file :
-----in settings.py-----------
BASE_DIR = Path(file).resolve().parent.parent

STATIC_URL = ‘/static/’

if (DEBUG == ‘True’):
“default”: {
“ENGINE”: “django.db.backends.sqlite3”,
“NAME”: BASE_DIR / “db.sqlite3”,

else :
STATIC_ROOT = os.path.join(BASE_DIR, ‘staticfiles’)
STATICFILES_STORAGE = ‘whitenoise.storage.CompressedManifestStaticFilesStorage’

'default': dj_database_url.parse(os.getenv("DATABASE_URL"))


MEDIA_URL = ‘/media/’
MEDIA_ROOT = os.path.join(BASE_DIR, ‘media’)

--------------------in urls.py------------------------
static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
note : i use postgres database in production

Hi there,

This is likely because the images are not being persisted. I recommend checking out our docs on persistent disks: https://docs.render.com/disks


Render Support Engineer, MT (UTC-6, UTC-7 in Winter)

1 Like