WebP is not compatible with S3FS module

Created on 15 December 2021, almost 3 years ago
Updated 12 June 2024, 5 months ago

Problem/Motivation

I have tried to use this module on a site that is using s3fs. The public files are on a s3 bucket. I can not see the derivatives images being generated on s3 nor loaded in the browser, No logs or messages are reported neither.

Browsing into the code I can see that webp is doing an altering of some routes, like image.style_public, in order to set his own controller. https://git.drupalcode.org/project/webp/-/blob/8.x-1.x/src/Routing/Route...

S3FS has his own controller to manage image styles that are being stored in s3 https://git.drupalcode.org/project/s3fs/-/blob/8.x-3.x/src/Routing/S3fsI...

I think webp needs to be able to manage the s3fs controller for derivatives images as well. Otherwise no derivatives images will be generated on the s3 bucket.

Steps to reproduce

- Install s3fs module
- Configure the module to send public files to the bucket (nothing locally).
- Install webp, set the styles as the documentation
- The webp images will not be created in the bucket, the images will not be show in the browser, no warnings nor messages are reported.

Proposed resolution

As a simple experiment I have tried to do the same alter for the route of the s3fs module and everything seems to work.

/**
 * Class RouteSubscriber.
 *
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
   foreach (['image.style_public', 'image.style_private'] as $route_id) {
      if ($route = $collection->get($route_id)) {
        $route->setDefault('_controller', 'Drupal\webp\Controller\ImageStyleDownloadController::deliver');
      }
    }

    foreach (['system.private_file_download', 'system.files'] as $route_id) {
      if ($route = $collection->get($route_id)) {
        $route->setDefault('_controller', 'Drupal\webp\Controller\FileDownloadController::download');
      }
    }

    if ($route = $collection->get('s3fs.image_styles')) {
      $route->setDefault('_controller', 'Drupal\webp\Controller\ImageStyleDownloadController::deliver');
    }

  }

}

Maybe this is something that can work to solve the issue.

Remaining tasks

Will be nice to add in the docuemntation of the module that s3fs integration is not functional, so other developers wont waste time trying to use this module until it works well.

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

🇦🇷Argentina casivaagustin

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Tested on Drupal 10.2.6 / S3FS 8.x-3.4 / WebP 8.x-1.0-rc2 with responsive image style and I can confirm that patch #7 works with this configuration and Webp images are correctly created in the bucket.

  • Curious, we also ran into this issue but did not install the WebP module (so the patch didn't work because there was nothing to patch). Does it make sense for us to install webp and then the patch for WebP to work with Drupal 9?

Production build 0.71.5 2024