matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.24k stars 276 forks source link

Trouble using S3 for Originals and Local Storage for Thumbnails #571

Closed lmuenter closed 3 months ago

lmuenter commented 4 months ago

Hello,

Due to project constraints I have to host my thumbnails locally. Uploaded Images are hosted in a custom, very limited S3-based cloud storage.

I love using django-imagekit, as its on-demand thumbnailing is exactly what I want to achieve. However right now, I fail at correctly specifying the storage backend, and tell imagekit that the images are to be retrieved from S3.

How can I correctly configure imagekit to use the local media folder to host images? The Setup works marvelously well if uploaded images and thumbnails are stored in the same location (when removing the S3 setup).

Settings

# MEDIA
MEDIA_ROOT = str(APPS_DIR / "media")
MEDIA_URL = "/media/"

# S3
AWS_ACCESS_KEY_ID = env(...)
AWS_SECRET_ACCESS_KEY = env(...)
AWS_STORAGE_BUCKET_NAME = env(...)
AWS_S3_ENDPOINT_URL = env(...)
DEFAULT_FILE_STORAGE = "custom_storage_backend_to_custom_s3.storages.MediaRootArunaBoto3Storage"

I then explored setting Imagekit's storage backend to django's standard FileSystemStorage like so:

IMAGEKIT_DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"

However, Imagekit fails at writing the thumbnails to the local media's /CACHE/images/:

python manage.py generateimages
Validating generator: imagekit:thumbnail
Validating generator: datasets:capture:thumbnail_small
  CACHE/images/<prefix>/<image>/eb740872bdf05a677d0abe9a67f1933d.jpg
        Failed Max Retries Exceeded
  CACHE/images/<prefix>/<image>/fe5609a2fbe4e11cfe38428547ee6451.jpg
        Failed Max Retries Exceeded

  [...]

I would be happy for any advice! Thanks in advance.

lmuenter commented 3 months ago

Closed this issue. The problem was my setup, and the lack of a dedicated storage class that retrieves from S3 and writes to File System.