In the current implementation of Payload, the default behaviour for Media/Uploads enforces that file names must be globally unique. My team and I have invested significant effort in integrating the S3 storage plugin, enabling folder structures, and adjusting indexes to deliver a more intuitive media management experience. Specifically, we have aligned the uniqueness constraint to require image names to be unique only within their respective folders, utilizing a composite index of file name and prefix to enforce this.
Functionality works as expected for media organization and storage. However, we have encountered a limitation when retrieving images via the API endpoint: http://localhost:3000/api/media/file/blocks.jpg
At present, the API solely uses the image name to perform a lookup for the S3 prefix. When multiple images with the same name exist in different folders, the API’s response (using docs[0]) does not guarantee that the correct file is returned.
Proposed Enhancement: I'd like to propose adding an optional query parameter to the API to allow passing the prefix when it is known, for example: http://localhost:3000/api/media/file/blocks.jpg?prefix=UUID
This would provide a straightforward solution to precisely identify and fetch the correct file, without the need to develop a custom endpoint or duplicate existing logic for secure file streaming from S3.
I believe this enhancement would greatly improve the developer and user experience for managing media in Payload. I’d be happy to further discuss the implementation or contribute a pull request if there is interest.