twill icon indicating copy to clipboard operation
twill copied to clipboard

Bug: Incorrect UUID stored in media table breaks Glide image rendering

Open Wanjiaa opened this issue 6 months ago • 0 comments

Description

When uploading a media file using the local media endpoint, the storeFile method in MediaLibraryController incorrectly constructs the uuid by concatenating the folder name and the filename:

$uuid = $request->input('unique_folder_name') . '/' . $filename;

This leads to the full path (e.g., uuid/filename) being stored in the uuid column of the media table.

This breaks image serving via Glide, which expects the uuid to match only the folder name portion (e.g., uuid). As a result, all /img/{uuid}/{filename} routes return a 400 Bad Request error.

Steps to reproduce

  1. Upload an image via the media library (local disk).
  2. Observe that in the media table:
    • uuid column contains: some-uuid/dummy-img.png
    • filename is: dummy-img.png
  3. Try to access the image via the generated Glide URL:
    /img/some-uuid/dummy-img.png
    
  4. Receive a 400 error.

Expected result

The uuid column should only store the folder/UUID value (e.g., some-uuid)
Glide should be able to resolve the image with:

/img/{uuid}/{filename}

Actual result

  • uuid stores uuid/filename
  • Media::where('uuid', $uuid) fails
  • Glide returns 400 Bad Request

Suggested fix

In storeFile():

- $uuid = $request->input('unique_folder_name') . '/' . $filename;
+ $uuid = $request->input('unique_folder_name');

Versions

  • Twill version: 3.5.2
  • Laravel version: 11.45.1
  • PHP version: 8.2
  • Database engine: MySQL

Wanjiaa avatar Jun 24 '25 11:06 Wanjiaa