Allow slashes in filenames #2911
Replies: 4 comments 2 replies
-
|
100% - I was just about to raise a discussion about this having been fighting for a couple of days to get Payload to behave the way I want it to....... I think this might be a fairly easy answer. Example use case:
Previous solution (not on Payload):
Payload currently doesn't allow "/" in the filename and expects all filenames to be unique across the whole application which is enforced by a unique index on filename in MongoDB which is automatically added on startup. There is a way to manipulate the prefix on the cloud storage plugin to be dynamically named which means that you can write files to folders in cloud storage via upload field but as this is the prefix it doesn't change the filename. Payload checks for the file existence when image1.jpg is uploaded for the second user and doesn't take the prefix into account. The file is saved into the second folder but when MongoDB is updated it throws a unique error on the filename as it sees 2 "image1.jpg" filenames. Allowing "/" in the filename would mean that the full name is stored in MongoDB and the unique index would still be valid. At the moment I have to avoid using the upload enabled collections on Payload and just store URLs to storage as text which isn't ideal :-( @PatrikKozak did you find any workaround? Can I influence the MongoDB index to use prefix and filename fields together? References: Uniqueness & santization (I want to avoid this!) Folder view- this might be part of the solution |
Beta Was this translation helpful? Give feedback.
-
|
I stumbled across this issue while migrating a set of Wordpress uploads to payload. The WP URL pattern I wound up using some Next js middleware hackery to mostly sidestep this limitation. But IMO a cleaner solution would be to expose a |
Beta Was this translation helpful? Give feedback.
-
|
Has this been solved? |
Beta Was this translation helpful? Give feedback.
-
|
Adding here to hopefully bump this again. I'm working with the Google Cloud Storage adapter and was able to successfully add a folder structure/file path through the use of the The issue I'm running into is being able to read/use the file. I know the admin thumb needs to be redirected, but I cannot for the life of me get the folder'd files to be found. I was able to append the prefix on read, but that responds with a 404 because it's not altering the file path to be read, but the API route to read from which is the 404. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Being that most blob storage "folders" are really just files with slashes in them, might consider ability to upload files that contain slashes in their filenames so that they are uploaded to "folders".
The problem is, we use the
sanitize-filenamepackage which automatically removes slashes from filenames - so we should figure out a way to either allow slashes specifically or have an option to opt out of filename sanitization.Beta Was this translation helpful? Give feedback.
All reactions