jeanbmar / payload-s3-upload

Send Payload CMS uploads to Amazon S3
MIT License
56 stars 9 forks source link

Error upon Modifying existing item #10

Closed nirsancho closed 1 year ago

nirsancho commented 1 year ago

Hi, I'm having an error after editing a field (not the files field) and cannot Save the item.

This is the error: TypeError: Cannot read properties of undefined (reading 'data') at getFilesToUpload (./node_modules/payload-s3-upload/dist/buildUploadHook.js:23:29) at ./node_modules/payload-s3-upload/dist/buildUploadHook.js:40:23

"data" referred in the error, is the actual upload file.

I believe the reason for the error, is that upon editing and saving (for example the "author" of the item) there is not an actual file being uploaded, so this hook should be completely skipped.

To reproduce the bug:

  1. Create an upload collection with a field for "name" - { name: "name", type: "text"}
  2. Create an item though the CMS interface (upload a file, set a name - "test1")
  3. Modify the name to "test2" and save
  4. Error: Cannot read properties of undefined (reading 'data')

Hope this helps Nir

jeanbmar commented 1 year ago

Hello there!

Thank you for the clear explanation! I've fixed the issue in https://github.com/jeanbmar/payload-s3-upload/pull/11

Cheers

nirsancho commented 1 year ago

Tested and fix verified!

Works like a charm! Thank you