decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

How to auto rename the file name of uploaded file or image?

Open alexliyu7352 opened this issue 8 years ago • 15 comments

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

alexliyu7352 avatar Dec 01 '17 16:12 alexliyu7352

reasons

  1. overwrites
  2. add the date-time or other prefix to file name is good for manager. like slug
  3. good for privacy protection, Because many files`s name is privacy

alexliyu7352 avatar Dec 01 '17 18:12 alexliyu7352

I think guys need this feature.Because many guys do not want to change local file name before upload.

alexliyu7352 avatar Dec 01 '17 18:12 alexliyu7352

This shouldn't happen by default, but should be possible through config, agreed.

erquhart avatar Dec 09 '17 07:12 erquhart

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:

  1. 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.

DomtronVox avatar Feb 25 '18 22:02 DomtronVox

@tech4him1 doesn't your slug sanitization work provide a solution for this?

erquhart avatar Feb 27 '18 22:02 erquhart

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.

tech4him1 avatar Feb 27 '18 22:02 tech4him1

Also @DomtronVox, uploading an image of the same name as an existing image currently triggers a prompt, it won't just overwrite.

erquhart avatar Feb 28 '18 00:02 erquhart

It would be good if panel prompted the name before commit. As the config option.

vintprox avatar Apr 16 '18 11:04 vintprox

@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?)

pungggi avatar Jun 07 '18 08:06 pungggi

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:

  1. Make filenames editable.
  2. 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).

erquhart avatar Jun 11 '18 20:06 erquhart

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.

stale[bot] avatar Oct 29 '19 15:10 stale[bot]

I am not familiar with the codebase. Where should I look to allow renaming a file prior to upload in the UI?

belmarca avatar Sep 22 '20 15:09 belmarca

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

Soneji avatar May 05 '21 11:05 Soneji

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

erezrokah avatar May 05 '21 13:05 erezrokah

:+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:

treshenry avatar Jan 11 '22 10:01 treshenry