Image styles - thumbnails are broken in config page when private file system is used

Created on 13 April 2020, over 4 years ago
Updated 11 March 2024, 10 months ago

Problem/Motivation

While using private files to create image styles, thumbnail images are broken.
Thumbnails are being created on the server, but Drupal can't seem to find them to display.

System says that private file path is writeable and is also not the problem with .htaccess.

I have tried to fix the issue with the below patch. please let me know if this works or someone has a better solution.

This has been reported here as well
https://www.drupal.org/forum/support/post-installation/2020-01-15/image-... โ†’

Steps to reproduce

To replicate the issue, Change the file system like below
Configuration->Media->File system -> Default download method (Set to private)

and then go to Configuration->Media->Image Styles->Edit style (Any style).

The system successfully writes the thumbnail file to the private folder, and I can download and view the file. (Attempting to access the private path in the browser gives a "page not found" result).

Proposed resolution

- Generate an 'itok' token for a sample preview image on the Image Style admin page.
- Grant access in image_file_download if the image path corresponds to preview image.

$samplePath = \Drupal::config('image.settings')->get('preview_image');
  if ($path === $samplePath) {
    $image = \Drupal::service('image.factory')->get($samplePath);
    return [
      // Send headers describing the image's size, and MIME-type.
      'Content-Type' => $image->getMimeType(),
      'Content-Length' => $image->getFileSize(),
      // By not explicitly setting them here, this uses normal Drupal
      // Expires, Cache-Control and ETag headers to prevent proxy or
      // browser caching of private images.
    ];
  }

Questions about security were answered in #12 ๐Ÿ› Image styles - thumbnails are broken in config page when private file system is used RTBC

Remaining tasks

- Waiting for review

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

๐Ÿ› Bug report
Status

Fixed

Version

10.2 โœจ

Component
Image moduleย  โ†’

Last updated 2 days ago

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia AmbyH

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024