SmileyChris / easy-thumbnails

Easy thumbnails for Django

Home Page:http://easy-thumbnails.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does WebP workaround work with AWS S3?

HenryMehta opened this issue · comments

This is really just a question but I've implemented the WebP workaround proposed but it doesn't seem to work for me and I cannot understand what I've done wrong.

In my apps.py I have

from django.apps import AppConfig
from django .conf import settings 

import logging
logger = logging.getLogger('debug')

def store_as_webp(sender, **kwargs):
    '''
    Stores new images in next gen format for improved website performance (particularly mobile)
    '''
    logger.info(f'Signal store_as_webp called in core')
    logger.info(f'Name: {sender.name}')
    #webp_path = f'{settings.MEDIA_URL}{sender.name}.webp'
    webp_path = sender.storage.path('.'.join([sender.name, 'webp']))
    logger.info(f'webpath: {webp_path}')
    sender.image.save(webp_path, 'webp')
    logger.info('WebP Saved')

class CoreConfig(AppConfig):
    name = 'core'

    def ready(self):
        from easy_thumbnails.signals import thumbnail_created
        thumbnail_created.connect(store_as_webp)

The first 2 logger lines are printed, then nothing so something is going wrong but I do not understand what. Any help would be appreciated

You are not alone, i'm hitting the same issue have you find a solutions ?

Regars

I did find the solution but cannot remember what it was. I'm running it on a Ubuntu PC and there was something I didn't have downloaded. Once done it worked fine. It was some webp program needed for Linux. I just don't remember what - sorry

I have analized with more details the problem.
if you have the implementation reported in documentations is impossible it is worling with s3.
sender.storage.path
is not defined in s3 implementations, the it will return NotImplementedError
rewrite store_as_webp as:

def store_as_webp(sender, **kwargs):
    s3_image_path = '.'.join([sender.name, 'webp'])
    _, fname = tempfile.mkstemp(dir="/tmp/")
    sender.image.save(fname, 'webp')
    f = open(fname, "rb")
    sender.storage.save(s3_image_path, f)
    f.close()
    os.unlink(fname)