usememos / memos

An open source, lightweight note-taking service. Easily capture and share your great thoughts.
https://usememos.com
MIT License
30.2k stars 2.26k forks source link

The image with the same name will be overwritten #3177

Closed LxnChan closed 5 months ago

LxnChan commented 5 months ago

Describe the bug

Uploading a file with the same name in the resources will cause the previous file to be overwritten. I'm using Cloudflare R2 as a backend here, and it's not clear at this time whether the other way would result in an override.

The usual practice in this place should be to upload the image and then change the name of the image to its SHA value, timestamp or some other random string to avoid being overwritten by the upload.

Steps to reproduce

  1. Use Cloudflare R2 Storage as a storage service.
  2. Prepare an image named 1.png
  3. Upload that image to the repository.
  4. In preparing a completely different image, also named 1.png
  5. Upload that image to the repository.
  6. Observe that the previously uploaded 1.png was overwritten.

The version of Memos you're using

Version: v0.20.1

Screenshots or additional context

image

LxnChan commented 5 months ago

As you can see from the Cloudflare dashboard it is directly uploaded with the original filename, so it will result in the file with the same name being overwritten when it is uploaded again.

image

EricWvi commented 5 months ago

The same here, using Minio as storage backend. 🧐

EricWvi commented 5 months ago

It is not easy to use when i want to paste multiple images, they are all named image.png OS: MacOS Software: Alfred Clipboard History enabled

EricWvi commented 5 months ago

The same here, using Minio as storage backend. 🧐

Maybe we can add a rename step when pasting images. Not familiar with TypeScript, sorry for not able to make a PR 😔

ntheanh201 commented 5 months ago

I think we can rename the images with a unique/random id, I'll take a look to the code

boojack commented 5 months ago

There should be a "Storage Path" setting item in the storage. You can set a "timestamp" placeholder for it to enable unique filename.

image

Learn more in https://www.usememos.com/docs/advanced-settings/local-storage