I have a fresh composer install of drupal 8 on Freebsd. When I try to upload any jpg/gif/png file to media browser file is uploaded correctly, but thumbnail is not generated.
I can observe the uploaded file in the list of media files but thumbnail is broken.
The uploaded file may be opened correctly and have URL like /sites/default/files/2020-03/filename-11_6.jpg.
The URL of thumbnail is like /sites/default/files/styles/thumbnail/public/2020-03/filename-11_6.jpg?itok=ducg-SU7.
The /sites/default/files/styles/ folder is empty. It have permission 777.
I have try to create appropriate folders structure inside the /sites/default/files/styles folder but thumbnails are still not generated. Manually created folders are removed when I flush at the /admin/config/media/image-styles

How can I force Media to work properly?

WORKAROUND / RESOLUTION:

for Nginx systems:

https://www.drupal.org/project/drupal/issues/3120676#comment-13764129

remove nginx directive

# Set images and js to expire in a very long time
location ~* \.(ico|css|pdf|jpg|jpeg|png|gif|js|xml|js|woff|woff2|ttf|svg|eot)$ {
expires 7d;
}

then all thumbnails under sites/default/files/styles/ should be generated and visible.

Remaining tasks

Investigate if feasible to create a patch for hook requirements implementation that would validate a correctly configured Nginx server configuration for styles, this would provide help text if the configuration is determined to be incorrect.
Apache2 doesn't seem to have this problem but perhaps a similar configuration in Apache2 might cause issues, the same hook requirements validation might be best to validate image style creation and file_exists in a generic way for any server type

if feasible, create patch

Issue fork drupal-3120676

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

a_sh created an issue. See original summary.

joseph.olstad’s picture

Rather than use the media module (contrib project) you should be using the core media module (the one provided by core)

from this contrib module page:

Drupal 8

Drupal core version 8.4 now includes a media module with similar functionality. In #2831274: Bring Media entity module to core as Media module: Bring Media entity module to core as Media module core adopted media namespace to add support for full-featured media entities. In case you are using the 8.3.x contrib media on your sites you need to uninstall it and remove it from the codebase before updating to Drupal 8.4. This doc might help answer how to configure the 'core' module

joseph.olstad’s picture

Status: Active » Postponed (maintainer needs more info)
joseph.olstad’s picture

keeping in mind, this functionality should now work ' out of the box' with drupal core 8.8.x +

So a core module (inclued with core) called media (same name) is included in Drupal 8 core version 8.4+ , and starting with 8.8+ theres advanced out of the box media functionality.

a_sh’s picture

Yes, I am using Media included into drupal installation

CORE

Manages the creation, configuration, and display of media items.
Machine name: media
Version: 8.8.4
Requires: FileFieldImageUserSystem

joseph.olstad’s picture

Project: D7 Media » Drupal core
Version: 8.x-1.x-dev » 8.8.x-dev
Component: Media Browser » media system
Category: Bug report » Support request
Status: Postponed (maintainer needs more info) » Needs review

Assigning issue to the correct queue. This is a CORE issue not a contrib module.

joseph.olstad’s picture

Status: Needs review » Active
a_sh’s picture

How can I track Drupal file operations?
I want to force drupal to log all file operations (especially file creation). Is it possible?

a_sh’s picture

It seems that issue is caused by some broken dependence....How can I check them?

joseph.olstad’s picture

inspect the element containing the link to the thumbnail, the styles path hints towards which image style (machine name) is being used. You can test the image style by providing a path to an image in the pattern that is found. Check your image styles, perhaps your server has insufficient write permissions to the sites/default/files/styles folder?

otherwise, check to see if that machine name image style exists, if not, create it.

does your server have sufficient write permissions to be able to write to the sites/default/files/styles folder?

or sites/{sitename}/files/styles folder if it is not default.

a_sh’s picture

The url of thumbnail is /sites/default/files/styles/thumbnail/public/2020-04/filename.jpg?itok=KBbfScLy
with class="image-style-thumbnail"
The corresponding image style exist, however corresponding folders are not created. I did try to add custom image style - the situation is the same.

I did try to create the appropriate folders structure inside the /sites/default/files/styles folder but thumbnails are still not generated. Manually created folders are removed when I flush at the /admin/config/media/image-styles
Imagick or GD - doesn't matter.

This problem shouldn't be related to permissions - styles is 777.
Problem is reproduced on two systems with Freebsd 12.1 and 10.4 (both nginx/php-fpm)

joseph.olstad’s picture

check the thumbnail image style in /admin/config/media/image-styles

alternatively, delete it, and then recreate it with the same settings.

see if this helps.

joseph.olstad’s picture

if you use imagick make sure you have the imagick dependencies installed on your server. check your reports log

a_sh’s picture

Yes, I did try to create a new image style and assign them to thumbnail. Not working.
Both imagick and GD show the same behavior - no thumbnails at all. \
There are no any strange errors in the log.

joseph.olstad’s picture

is your 'files' folder symlinked outside of somewhere?
or your styles folder, is it a symlink to somewhere?

are there other 'styles' that work? or is it just the thumbnails styles?

have you tried disabling the image module? and re-installing it?

have you done a config export and config import? is there config information that is causing a bad setting?

have you done a drush updb -y or visitted update.php when logged in? making sure you get schema updates?

what version of php are you using?

if you are using Linux, have you disabled selinux and disabled apparmor?

try disabling apparmor and make sure selinux is disabled, these two things can do weird things to your permissions and restrict things to the point that they stop working unless you really know how to use apparmor and selinux they should be disabled .

check with your operating system vendor for more details.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

DerekRoth’s picture

Hi,
I have the exact same issue:

  • thumbnails are not being generated
  • the permissions on the filesystem are OK, i confirmed this by writing a simple PHP script that creates directories and writes to them without Drupal, and it works when called through its URL
  • I have no errors in the logs

I'd like to dig into the code to see what is wrong and for this i need more information:

  • what is supposed to be the trigger to generate a thumbnail ? The HTTP request to its URL ?
  • what part of the code generates the thumbnail ?
  • what part of the code writes it to the filesystem ?

I'm running PHP 7.2, Drupal 8.7.13, GD2, Apache and the core Drupal module for media.

a_sh’s picture

Hi, DerekRoth

What OS are you running?

Haessler’s picture

I had the same issue: No thumbnails generated on a new install (D 8.9 PHP 7.4, Centos), styles folder remained empty. I removed a nginx directive

# Set images and js to expire in a very long time
location ~* \.(ico|css|pdf|jpg|jpeg|png|gif|js|xml|js|woff|woff2|ttf|svg|eot)$ {
expires 7d;
}

and all thumbnails under styles where generated and visible.
Ulli

athrylith’s picture

We have had a similar problem with a custom Warpwire OEmbed provider we've created. The problem seems to be in how the thumbnail url is being formed. Warpwire does not include an extension on thumbnails which causes line 396 in Drupal\media\Plugin\media\Source (D9.0.2)

$local_thumbnail_uri = "$directory/" . Crypt::hashBase64($remote_thumbnail_url) . '.' . pathinfo($remote_thumbnail_url, PATHINFO_EXTENSION);

to create a filename ending in '.', which is illegal, so no thumbnail is being created. We are currently testing a solution that uses GD2's getImageSize() to read the correct image type and append the correct extension.

phenaproxima’s picture

Status: Active » Needs work
Issue tags: -media thumbnail generate +Needs steps to reproduce

It would be really helpful to get steps to reproduce in the issue summary here, starting from a clean installation of Drupal core.

phenaproxima’s picture

a_sh’s picture

I had the same issue: No thumbnails generated on a new install (D 8.9 PHP 7.4, Centos), styles folder remained empty. I removed a nginx directive

# Set images and js to expire in a very long time
location ~* \.(ico|css|pdf|jpg|jpeg|png|gif|js|xml|js|woff|woff2|ttf|svg|eot)$ {
expires 7d;
}

and all thumbnails under styles where generated and visible.
Ulli

It works! Thank you very much!

joseph.olstad’s picture

Status: Needs work » Active

seeing as this is an nginx specific issue, is there anything we can do from the application side to mitigate this?

perhaps add a hook_requirements check for nginx that tests for this bad configuration?

joseph.olstad’s picture

Title: Media project do not generate thumbnails for uploaded images » NGINX configuration can interfere with generated thumbnails and image styles for uploaded images
joseph.olstad’s picture

Title: NGINX configuration can interfere with generated thumbnails and image styles for uploaded images » NGINX configuration options can interfere with generated thumbnails and image styles for uploaded images
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Category: Support request » Feature request
Status: Active » Needs work
stuiegreen’s picture

Worked for me. YEEESSSSSS!!!

gurunathan’s picture

The solution #19 says to remove the nginx directive.
How to do it?

Tunprog made their first commit to this issue’s fork.

tunprog’s picture

I had the same issue with image styles on Drupal 9 version 9.2.10. Fixed it by removing these lines from my nginx configuration file:

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
    }

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

marvs5’s picture

This is still an issue. I am running a D9 site on Nginx and it wasn't making the thumbnails until I removed the above Nginx location directive. Clearly this is still suboptimal.

Version: 9.2.x-dev » 9.3.x-dev
arturopanetta’s picture

Same problem for me too. Removing the NGINX rule makes the thumbnails visible again.
Drupal:9.3 (docker image)
NGINX:1.20 (docker image)

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

jukka792’s picture

I have same issue with D9.3.16
Image styles appears only after cron run. Nonen of the above mentioned nginx conf removals helped.
This is weird, it used to work and works in production but when site copied to local does not work. tried woth php 7.4 and 8.1

khurrami’s picture

#32 Worked for Thanks a lot.

brianwagner’s picture

I'm also seeing this issue with Drupal 9.4.5 on Debian, running Nginx 1.18.0. I modified the recommended Nginx Drupal config as mentioned above. No change.

The styles/ directory is not created at all. No error messages in Drupal, Nginx, or PHP-fpm. It's unclear where else to look for debugging info.

Youcanlearnit’s picture

I have same issue.
Folders are not created in styles folder, and thumbnail images are not created.
PHP 8.1.8
NGINX 1.18
Drupal 9.4.5

None of the fix to NGINX configurations helps.
Tried to change styles folder permissions but no help.
I have another production server with same site and server packages, and it does not have this issue.
Also my local environment has this issue. I have tried all possible things, but nothing looks to help.

vishnutrz’s picture

Hello @youcanlearnit

you can try this NGINX config file - https://www.nginx.com/resources/wiki/start/topics/recipes/drupal its works for us when face the same issue.

the link taken from https://www.drupal.org/project/drupal/issues/3285320 comment #7

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rowbotony’s picture

[~~~ Updated Comment #2 (Nov. 5, 2023) ~~~~]
Here's what the AI overlords have to say about, this fixed my specific problem on my local DDEV instance. I hope it helps others.

https://chat.openai.com/share/80e83546-b512-4a07-af75-789afe7be6a1

location ~* ^/sites/default/files/styles/ {
    try_files $uri $uri/ @rewrite;
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}

location @rewrite {
    rewrite ^/(.*)$ /index.php?q=$1;
}

[~~~ Original Comment #1 (Oct. 28, 2023) ~~~~]
Update with my own experience. I'm using DDEV with Acquia Migrate Accelerate to move a D7 site to D9. All of my images were broken and wouldn't display. The original images were there, media uploads worked fine, file system permissions were correct, PHP, GD, etc were good.

The DDEV seconddocroot.conf.example has the following line, when removed, then ddev restart, it worked - my images were back, and now the styles were being properly generated!

If you are running Nginx, and you have image generation problems, this is still relevant.

# Expire rules for static content
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}
poker10’s picture

Category: Feature request » Support request
Status: Needs work » Active

I am not sure where this directive come from:

# Set images and js to expire in a very long time
location ~* \.(ico|css|pdf|jpg|jpeg|png|gif|js|xml|js|woff|woff2|ttf|svg|eot)$ {
  expires 7d;
}

In all examples/recommended configs for Nginx I see that there is an additional line:

try_files $uri @rewrite;

See:

As far as I know, these configs are working without need to remove the whole directive used for caching static content.

The Issue summary should at least include the full nginx config used on sites experiencing this and clear steps to reproduce. Thanks!

Core currently does not supply an example nginx config unless this is in #2937161: Provide documentation/default server block for Nginx server., so I think that this seems like more a Support request (not sure anything can be done here until that issue is committed and there is an estabilished default config supported by core). So I think we can either make this a Support request, or postpone it.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Active » Fixed

I skimmed through the comments and all the reports are for currently unsupported versions of Drupal. Two years ago, in #45, @poker10 gave a solution. Therefor I am closing this support request.

The Drupal Core issue queue is not the ideal place for support requests. There are several support options listed on our Support page, including the Drupal Forums and Drupal Answers.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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