twill
twill copied to clipboard
Bug: Incorrect UUID stored in media table breaks Glide image rendering
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
- Upload an image via the media library (local disk).
- Observe that in the
mediatable:-
uuidcolumn contains:some-uuid/dummy-img.png -
filenameis:dummy-img.png
-
- Try to access the image via the generated Glide URL:
/img/some-uuid/dummy-img.png - Receive a
400error.
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
-
uuidstoresuuid/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