Error "Could not generate image resource from URI" on non-image formats

Created on 30 December 2021, over 2 years ago
Updated 15 August 2023, 11 months ago

Problem/Motivation

Creating a new issue from: #3221033: Error downloading a private file when the file is not an image

Errors are being generated when a website administrator clicks on a link to a private file that is not an image.

Could not generate image resource from URI private://example-file.pdf

Error originates from line 151 of src/Webp.php:

      else {
        $error = $this->t('Could not generate image resource from URI @uri.', [
          '@uri' => $uri,
        ]);
        $this->logger->error($error);
      }

No obvious side effects (file can still be viewed/opened).

Steps to reproduce

1. Complete and submit a webform that has an widget for uploading files to the private filesystem
2. View the submission via the webform UI
3. Click on the link to the submitted file
4. An error will be generated in the watchdog logs.

Proposed resolution

Not sure.

Rolling back to drupal/webp:1.0-beta5 resolves the error.

Possibly introduced with commit 61a1015 from #3143491: Private images support .

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇦Canada othermachines Edmonton, Alberta

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇸🇮Slovenia KlemenDEV

    #8 works and fixes the issue and is in my opinion better than #2.

    Did not test for MP4, so #7 still needs work. @Antares89, could you provide more info on what errors do you get?

    I think this is quite important issue and with any website with non-image file downloads, this can quickly spam the logs

  • 🇸🇮Slovenia KlemenDEV

    @mandclu asked for confirmations of open issues on #3290669 so we can get a new stable release, so here is another confirmation this is RTBC and working on our websites (we don't use mp4, though)

  • Status changed to RTBC about 1 year ago
  • 🇸🇮Slovenia KlemenDEV

    I can confirm again #8 works fine on multiple production sites and this issue seems RTBC and for release

    • mandclu committed 2b00b836 on 8.x-1.x
      Issue #3256454 by Ahmad Smhan, MakerTimSWIS: Error "Could not generate...
  • Status changed to Fixed 11 months ago
  • 🇨🇦Canada mandclu

    Thanks for everyone's work and feedback on this issue. I think relying on the isValid() method is a sensible approach, though probably not perfect in all cases. For the specific MP4 example, I understand that an MP4 container can contain still images (though it tends to be unusual) so I would say that that this is understandable. If it turns out to be a widespread concern, we can examine that in a separate issue, though this is arguably more of a core issue, since that is what makes the isValid() determination.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024