[Django]-How to programmatically store S3 images in Django

2👍

s3.ObjectSummary object may not be identified as an image object by Django.

Give this a try

from django.core.files.base import ContentFile

bucket = s3.Bucket('my-bucket')

for my_bucket_object in bucket.objects.filter(Prefix='media/upload/2020'):
    djfile = Media.objects.create(asset_title=my_bucket_object.key, image_file=ContentFile(my_bucket_object))  

The ContentFile class inherits from File, but unlike File, it operates
on string content (bytes also supported), rather than an actual file
documentation

Leave a comment