Allow slashes in filenames #2911
Replies: 2 comments 1 reply
-
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.
-
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-filename
package 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