Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only one file is saved when uploading multiple images in a multiple field. #9890

Closed
manutepowa opened this issue Dec 11, 2024 · 3 comments · Fixed by #9918
Closed

Only one file is saved when uploading multiple images in a multiple field. #9890

manutepowa opened this issue Dec 11, 2024 · 3 comments · Fixed by #9918
Assignees

Comments

@manutepowa
Copy link

Describe the Bug

When configuring an image field with the hasMany: true option, attempting to upload multiple files at once results in only one of the files being saved correctly in the database.

Link to the code that reproduces this issue

https://github.com/payloadcms/payload

Reproduction Steps

Video
https://github.com/user-attachments/assets/3ed984c0-f958-4d36-8c8d-7c2400cfad66

Field config.

{
  type: "upload",
  name: "gallery",
  label: "Galería de imágenes",
  relationTo: "media",
  hasMany: true,
}

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Payload v3.5.0
@manutepowa manutepowa added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 11, 2024
@manutepowa manutepowa changed the title Only One File Is Saved When Uploading Multiple Images in a Multi-Image Field Only one file is saved when uploading multiple images in a multiple field. Dec 11, 2024
@akhrarovsaid
Copy link
Contributor

@manutepowa Yup. Reproduced in monorepo _community folder with the config you provided, authoring a fix. I'd like to test a few things with the bulk uploads before making a PR but should have one out soon!

@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Dec 12, 2024
PatrikKozak added a commit that referenced this issue Dec 17, 2024
…ata overriding old docs (#9918)

<!--

Thank you for the PR! Please go through the checklist below and make
sure you've completed all the steps.

Please review the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository if you haven't already.

The following items will ensure that your PR is handled as smoothly as
possible:

- PR Title must follow conventional commits format. For example, `feat:
my new feature`, `fix(plugin-seo): my fix`.
- Minimal description explained as if explained to someone not
immediately familiar with the code.
- Provide before/after screenshots or code diffs if applicable.
- Link any related issues/discussions from GitHub or Discord.
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Fixes #

-->
### What?
This PR fixes an issue where bulk upload on an upload field with
hasMany, which had errors on sequential uploads, caused only the last
successful upload to be saved to the field value.

### Why?
To save all successful uploads to the field value and sync what was
shown in the ui to the actual field data.

### How?
By triggering a rerender that syncs `populatedDocs` to the fields
`value` on each sequential successful upload after form errors were
resolved.

Fixes #9890

Before:

[Bulk-upload-before--Post---Payload.webm](https://github.com/user-attachments/assets/6396a88b-21c2-4037-b1ef-fd7f8d16103f)

After:

[Bulk-upload-after---Payload.webm](https://github.com/user-attachments/assets/8566a022-6e86-46c7-87fe-78d01e6dd8c9)

Notes:
- The core issue was that onSuccess function was not properly syncing
the correct field values resulting in stale values that would overwrite
old docs.

---------

Co-authored-by: Patrik Kozak <patrik@payloadcms.com>
Copy link
Contributor

🚀 This is included in version v3.9.0

Copy link
Contributor

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants