Skip to content

Media: Send array values from the upload pipeline as arrays - #15146

Closed
aryanjasala wants to merge 3 commits into
WordPress:trunkfrom
aryanjasala:fix/media-pipeline-array-form-data
Closed

aryanjasala wants to merge 3 commits into
WordPress:trunkfrom
aryanjasala:fix/media-pipeline-array-form-data

Conversation

@aryanjasala

@aryanjasala aryanjasala commented Oct 29, 2026 •

Copy link
Copy Markdown

When several registered image sizes have the same dimensions, the Media Library upload pipeline sideloads one file for all of them and passes their names as an array in image_size. flattenFormData() in media-upload-pipeline.js appended that array as the string a,b, so the sideload endpoint returned 400 and those sizes were never created.

This makes flattenFormData() recurse into arrays as well as plain objects, the same as flattenFormData() in the media-utils package since WordPress/gutenberg#82353.

Testing: with two sizes registered at 320 by 320, uploading a JPEG from Media > Add New on 7.2-beta3-64990 returned 400 for one sideload and created neither size. With this change, every sideload returned 200 and both sizes are in the attachment metadata.

Trac ticket: https://core.trac.wordpress.org/ticket/66412

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Writing the patch and drafting this description. I reproduced the bug and tested the fix myself.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Proposed commit message

Claude Code drafted this commit message from the PR and the Trac ticket:

Media: Create image sizes that share dimensions on upload.

When client-side media processing is active and two or more registered image sizes have the same dimensions, the Media Library upload pipeline sideloads one file for all of them and sends their names as an array in `image_size`. `flattenFormData()` in `media-upload-pipeline.js` only recursed into plain objects, so the array was sent as a comma-separated string. The sideload endpoint rejected it with a 400 and none of those sizes were created, while the upload itself appeared to succeed.

Recurse into arrays as well as plain objects, matching `flattenFormData()` in the media-utils package since https://github.com/WordPress/gutenberg/pull/82353. This affects only Media > Add New and the Media Library grid. The block editor already handled arrays correctly.

Follow-up to [64588].

Reviewed by westonruter.

Props aryanjasala, ozgursar, dhrupo, jyria, kirasong, wildworks, westonruter.
Fixes #66412.

When several registered image sizes have the same dimensions, the upload pipeline sideloads one file for all of them and passes their names as an array in `image_size`. `flattenFormData()` in `media-upload-pipeline.js` turned that array into the string `a,b`, so the sideload endpoint rejected it and those sizes were never created.

This handles arrays the same way as the `flattenFormData()` in the media-utils package, which was fixed in Gutenberg PR 82353.

See #66412.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props aryanjasala, wildworks, adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@t-hamano
t-hamano requested review from adamsilverstein and a balanced review from Copilot November 23, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Media Library upload pipeline’s array-serialization change.

No open issues 🎉

What changed in this PR

Fixes array serialization in the Media Library upload pipeline so image sizes sharing the same dimensions can be sideloaded together without a 400 response.

Changes:

  • Makes flattenFormData() recursively serialize arrays into indexed form fields instead of comma-separated strings.
  • Updates the helper’s documentation to describe support for nested arrays.
File Description
src/​js/​_enqueues/​admin/​media-upload-pipeline.js Adds recursive array serialization and documents the supported input types.

Review effort: Balanced

@adamsilverstein adamsilverstein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good.

@adamsilverstein

Copy link
Copy Markdown
Member

This looks good to me, I'm going to add a test here then try to get a second approval so I can get this committed.

The existing client-side upload specs only check the default sizes, so they pass whether or not `flattenFormData()` sends the `image_size` array correctly, and the copy in core could lose its array handling again unnoticed.

Register two sizes with the same dimensions through a must-use plugin and assert that every sideload succeeds and both sizes are created. The plugin only acts on requests carrying this test's cookie, so other tests sharing the site are unaffected.

See #66412.

Claude-Session: https://claude.ai/code/session_018vwYjUKQHg7Dn2Lj1vTwmX
Comment on lines 64 to 66
Object.keys( data ).forEach( function ( name ) {
flattenFormData( formData, key + '[' + name + ']', data[ name ] );
} );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this seems slughtly better as:

for ( const [ name, value ] of Object.entries( data ) ) {
    flattenFormData( formData, `${ key }[ ${ name } ]`, value );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, I'll use that form in the future.

@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65748
GitHub commit: 5ae0af9

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants