payloadcms / plugin-cloud-storage

The official cloud storage plugin for Payload
MIT License
131 stars 36 forks source link

Replacing an upload's file doesn't remove the old file (GCS) #43

Closed qbeauperin closed 1 year ago

qbeauperin commented 1 year ago

Without the plugin, replacing a file with another will remove the old file(s). With it (I've only tested with the GCS adapter), they aren't, and the new files now exists alongside the old ones.

Additional weird behavior that popped up during testing:

  1. Create a new upload using the file image.jpg a. image.jpg is now in the bucket
  2. Replace image with another image.jpg a. image is automatically renamed image-1.jpg b. bucket now has an image.jpg AND an image-1.jpg
  3. Replace the image again with another image.jpg a. image is properly named image.jpg again b. in the bucket, image.jpg has been replaced with the new image.jpg, but image-1.jpg is still present
  4. Delete the upload altogether a. Only the "current" file will be deleted from the bucket, the old ones will stay, seemingly forever
ahmedHusseinF commented 1 year ago

tested the issue and it seems to happen on AWS S3 as well

the issue is happening at exactly this line https://github.com/payloadcms/plugin-cloud-storage/blob/2f799a9420551b7999bc9f12f822fdb37042503b/src/hooks/beforeChange.ts#L18

No checking on the operation if it is an update to delete the old file

jmikrut commented 1 year ago

Hey @qbeauperin and @ahmedHusseinF — this is now fixed and will be released shortly! Thank you for the report!

qbeauperin commented 1 year ago

Looking forward to it, thank you James! 🙌