silverstripe / silverstripe-asset-admin

Silverstripe assets gallery for asset management
BSD 3-Clause "New" or "Revised" License
19 stars 78 forks source link

Thumbnails in CMS File system not showing up in Subfolders #1459

Closed draghu9 closed 1 month ago

draghu9 commented 1 month ago

Module version(s) affected

2.2.0

Description

Silverstripe Framework version 5.2.6 Asset admin version 2.2.0 Operating in clean Silverstripe install with no customizations

Uploading images in the CMS Files system is working but thumbnails are not showing up upon Publish. This is happening at the sub directory level. Example If we create a folder structure in Files as Files->Level1->Level2->Level3 and Upload an image at directory Level 3 and publish the thumbnail is missing.

I have checked the image src and the problem seems to be missing forward slashes (/) that separates the sub directories. Adding the forward slashes in the path via Inspect Element showed me the thumbnail.

Following GIF should represent what I mentioned above.

SS_Thumbnail

How to reproduce

  1. Login to CMS running on Silverstripe framework 5.2.6 and Admin-Assets 2.2.0
  2. Navigate to Files section from Left hand menu
  3. Create nested sub-directories. Example Files->Level1Directory->Level2Directory->Level3Directory
  4. Upload an image in Level3Directory
  5. Publish

Possible Solution

Navigating through the code I found there is a function called generateThumbnailLink(AssetContainer $file, $width, $height, $graceful = false) in ThumbnailGenerator.php file.

$result = $this->generateLink($thumbnail); gives the missformed thumbnail URL with all backslashes adding str_replace("\","\/",$result); seems to resolve the issue.

Additional Context

No response

Validations

PRs

emteknetnz commented 1 month ago

I'm unable to replicate this.

Is your webserver running Windows?

Could you try updating vendor/silverstripe/assets/src/Flysystem/PublicAssetAdadter::getPublicUrl() to the following:

    public function getPublicUrl($path)
    {
        $path = Convert::slashes($path, '/'); // this line is new
        return Controller::join_links(Director::baseURL(), $this->parentUrlPrefix, $path);
    }

And let me know if that fixes the issue?

draghu9 commented 1 month ago

I have done the changes as you mentioned, and it seems to have fixed the issue. Also Yes, my web server is running on Windows

GuySartorelli commented 1 month ago

PR merged. This will be automatically tagged by GitHub actions.