feat: add new source.uploadMedia API - #645
Merged
Merged
Conversation
…bugs Adds tests for the new source.uploadMedia API (legacy FormData delegation with the stage content.da.live -> stage-content.da.live rewrite, hlx6 media POST with content-type + contentUrl normalization, non-ok passthrough, and the path-string call form). Writing the tests surfaced two bugs in the uncommitted uploadMedia implementation, both fixed here: a fallthrough that made non-hlx6 uploads also hit the hlx6-only media endpoint, and a body-stream-already-read bug where a successful non-hlx6 response without a content.da.live host was returned after its body had already been consumed.
tripodsan
commented
Aug 6, 2026
tripodsan
commented
Aug 6, 2026
Comment on lines
+782
to
784
| function adaptJsonResponse(resp, obj) { | ||
| return new Response(JSON.stringify(obj), resp); | ||
| } |
kptdobe
previously approved these changes
Aug 7, 2026
kptdobe
approved these changes
Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
source.uploadMedia({ org, site, path, body })API innx2/utils/api.js: legacy delegation to_saveDAas FormData (including the stagecontent.da.live→stage-content.da.livecontentUrl rewrite), hlx6 POSTs to the AEM media route with the correctcontent-typeheader,contentUrlprefix-normalization against the site'saem.pageorigin, non-ok passthrough for both branches, and the/org/site/pathstring call form.uploadMediaimplementation:DA_ADMINwasn't exactly'https://stage-admin.da.live'— i.e. for ordinary non-hlx6 sites in most environments,uploadMediamade an unintended second request after_saveDAhad already completed. Fixed by returning unconditionally after the_saveDAcall.DA_ADMINis'https://stage-admin.da.live', so the stage-content rewrite branch always runs for non-hlx6 uploads. When the returnedcontentUrl's host wasn'tcontent.da.live(no rewrite needed), the code had already consumed the response body viaresp.json()and then returned that same drainedResponse— any caller callingresp.json()again would hit a "body stream already read" error. Fixed by always returningadaptJsonResponse(resp, json)in that branch.Test plan
npm run test:file -- ./test/nx2/utils/api.test.js— 120/120 passing (11 new tests foruploadMedia)npm test(full suite) — all tests pass in isolation; the shared full-suite run is intermittently flaky under--concurrent-browsers 4on unrelated test files (pre-existing, not touched by this change)npx eslint nx2/utils/api.js test/nx2/utils/api.test.js— clean🤖 Generated with Claude Code