RESOLVED DUPLICATE of bug 319396320904
XHR multipart/form-data file upload sends Content-Length: 0 and drops file content on Safari 26.5.2
https://bugs.webkit.org/show_bug.cgi?id=320904
Summary XHR multipart/form-data file upload sends Content-Length: 0 and drops file co...
contact
Reported 2026-08-03 06:49:50 PDT
Created attachment 480916 [details] developper tools inspector SUMMARY: On Safari 26.5.2, submitting a multipart/form-data request built from a FormData object via XMLHttpRequest (jQuery $.ajax) fails to transmit the selected file's content. The request that actually leaves the browser has Content-Length: 0 and an empty body, even though the file part's headers (Content-Disposition, Content-Type) are present in the request as captured by Web Inspector. The server receives no data at all, not even the non-file form fields. This reproduces with any file, regardless of size or type -- confirmed with a 113 KB PDF, so it is not related to any size limit. STEPS TO REPRODUCE: 1. Load a page containing a form (enctype="multipart/form-data") with a text input and an input type="file". 2. On the file input's change event, build a FormData from the form and POST it via XMLHttpRequest (or $.ajax) to an endpoint, instead of a native form submit. 3. Select a small file (e.g. a PDF under 200 KB) from the Files/Photos picker. 4. Inspect the outgoing request in Web Inspector or via a HAR export. ACTUAL RESULTS: - The request is sent with header Content-Length: 0. - The captured request body shows the multipart parts (text fields, and the file part's Content-Disposition: form-data; name="file";filename="document.pdf" / Content-Type: application/pdf headers) but the byte content between the file part's headers and the next boundary is empty. - The server (in our case a PHP/Drupal backend) receives an empty request body and no POST fields at all -- not just the file field, but every other text field in the same multipart body is also missing. EXPECTED RESULTS: The full multipart body, including the file's binary content, should be sent with a correct, non-zero Content-Length, matching the behavior seen on Safari on iOS 18 and on other browsers. CONFIGURATION: - Failing: Safari 26.5.2 (User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5.2 Mobile/15E148 Safari/604.1). Note the OS reports 18.7 while the Safari engine itself is 26.5.2, so this appears tied to the Safari/WebKit version rather than the iOS major version. - Working: Safari on iOS 18 (older Safari version on the same site/code path). - Device: iPhone. ADDITIONAL NOTES: This was found on a production Drupal 10 site, where the JS upload pathway is Drupal core's managed_file widget (core/modules/file/js/file.js, Drupal.file.triggerUploadButton), which auto-submits the enclosing form via Drupal.ajax (jQuery $.ajax, FormData) as soon as a file is selected, rather than on a full native form submit. The bug appears specific to this JS-driven XMLHttpRequest/FormData upload path, since we have not observed the same failure on a plain native form submit (browser-driven navigation, not JS-driven XHR) on the same Safari version -- though this hasn't been isolated into a minimal public test case yet. SEE ALSO: - bug 184490 -- REGRESSION (r221839): Submitting a form with XMLHttpRequest fails when the form has an empty file input element. Different trigger condition (empty file input), but same general class of "multipart form submission via XHR silently drops content" bug. - bug 165081 -- Unable to post File data in Safari 10 with a XHR POST request. Different trigger condition (File constructed via window.File() losing its internal path), but same end symptom: the request goes out with no actual file data attached. Neither of these matches our exact reproduction (a real file picked through the native Files/Photos picker, on current Safari 26.5.2), so this is filed as a new, separate report.
Attachments
developper tools inspector (313.13 KB, image/png)
2026-08-03 06:49 PDT, contact
no flags
Alexey Proskuryakov
Comment 1 2026-08-03 15:18:49 PDT
*** This bug has been marked as a duplicate of bug 319396 ***
Note You need to log in before you can comment on or make changes to this bug.