How can I upload media files to amazon s3?

0

I have a project in django that I am trying to migrate to Amazon s3. Within the project I use the easy_thumbnails package (I leave the documentation here ).

I have everything configured to send the images to Amazon S3 but I can not get the thumbnails sent to that route and I do not know exactly what is happening.

I leave my configuration of the AWS, the settings and the model.

AWS

import datetime
AWS_ACCESS_KEY_ID = "xxxxx"
AWS_SECRET_ACCESS_KEY = "xxxx"
AWS_FILE_EXPIRE = 200
AWS_PRELOAD_METADATA = True
AWS_QUERYSTRING_AUTH = True


DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_STORAGE_BUCKET_NAME = 'cdn.dev.chikka.com.co'
S3DIRECT_REGION = 'us-east-1'
S3_URL = '//%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
MEDIA_URL = '//%s.s3.amazonaws.com/media/' % AWS_STORAGE_BUCKET_NAME
MEDIA_ROOT = MEDIA_URL

two_months = datetime.timedelta(days=61)
date_two_months_later = datetime.date.today() + two_months
expires = date_two_months_later.strftime("%A, %d %B %Y 20:00:00 GMT")

AWS_HEADERS = {
    'Expires': expires,
    'Cache-Control': 'max-age=%d' % (int(two_months.total_seconds()), ),
}

CLOUDFRONT_DOMAIN = 'cdn.dev.chikka.com.co'
CLOUDFRONT_ID = "xxxxxx"
AWS_S3_CUSTOM_DOMAIN = 'cdn.dev.chikka.com.co'

Settings

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static_cdn') # Cuando hacemos collectstatic

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

#thumbnail S3
THUMBNAIL_DEFAULT_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

Model

class Foto(models.Model):
    id = models.BigAutoField(primary_key=True)
    path = ThumbnailerImageField(upload_to='imagenes/productos',resize_source=dict(size=(1200, 0), sharpen=True))
    producto = models.ForeignKey(Producto,on_delete=models.CASCADE, related_name='imagenes')

    def filename(self):
        return os.path.basename(self.path.name)
    
asked by F Delgado 22.10.2018 в 18:15
source

0 answers