How to auto rename the file name of uploaded file or image?
How to auto rename the file name of uploaded file or image? I mean when i upload an image or file, how to auto rename it?like slug, or use timestamp to file name
reasons
- overwrites
- add the date-time or other prefix to file name is good for manager. like slug
- good for privacy protection, Because many files`s name is privacy
I think guys need this feature.Because many guys do not want to change local file name before upload.
This shouldn't happen by default, but should be possible through config, agreed.
I would like to add a 4th to the list. Recently I had an issue with a non-technical person uploading an image that had special characters (in my case the # sign) causing the static site to have an error during its' build. So:
- Allows sanitizing uploaded file's name for technical reasons.
I think the fix for all these may need to be separate features though. 2-4 seem to work well with an automatic approach, but overwrites (no. 1) should probably have an option similar to delete in the media manager. Could be called reupload, but that might be too close to "upload" and be confusing to some.
You shouldn't be able to replace an image file just by uploading another of the same name as this could cause loss of data problems. So it should either follow a delete file -> upload new file pattern or have a special upload mode specifically for replacing.
@tech4him1 doesn't your slug sanitization work provide a solution for this?
4. Allows sanitizing uploaded file's name for technical reasons.
@tech4him1 doesn't your slug sanitization work provide a solution for this?
Sanitizing media filenames is part of https://github.com/netlify/netlify-cms/pull/1135.
Also @DomtronVox, uploading an image of the same name as an existing image currently triggers a prompt, it won't just overwrite.
It would be good if panel prompted the name before commit. As the config option.
@erquhart Can we agree on the options ?
Suggestions:
| OptionField | Value | Behaviour |
|---|---|---|
| prompt | if option filename is not set, then same behaviou as of now | |
| prompt | true | prompts for a filename |
| filename | {{collection}}__{{year}}-{{month}}_{{filename}} |
composes filename. if prompt is set to true this is used as a suggestion |
Same tags available as https://www.netlifycms.org/docs/configuration-options/#slug In addition:
-
{{filename}}: original name of the file -
{{collection}}: name (or label?) of the collection -
{{myField}}: value of a custom field in the collection (< is this possible?) -
{{counter}}: a counter within a list or collection (< is this possible?)
Templated default filenames makes sense, as well as prefixing and only allowing the user to add/edit a portion of the resulting filename (maybe). That's separate from the core issue of making the filename editable though. We should split this issue into two concerns:
- Make filenames editable.
- Provide "slug" features for media filenames.
Editable filenames is mostly a UI problem. The more complex issue of creating and enforcing slugs is larger than the problem at hand (#445).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am not familiar with the codebase. Where should I look to allow renaming a file prior to upload in the UI?
Hi
Is this still something people want? I certainly would love to be able to rename my files/images before uploading them. If a maintainer could point me in the direction of the code for handling file uploads I would be happy to send a PR
Thanks
Hi @soneji, maybe we can do this as a part of https://github.com/netlify/netlify-cms/issues/4965?
The UI code for the media library is here https://github.com/netlify/netlify-cms/tree/master/packages/netlify-cms-core/src/components/MediaLibrary
:+1:
For another angle: I have clients that use an iPad to update content. It's awesome that they can select a photo from the iPhoto library on the device, however, iPhoto appears to export the image with a GUID file name. Being able to customize the file name at the time the file is uploaded would solve this issue. I mean, this is clearly iPhoto's fault... but since there's already a ticket open... :smile: