WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
Bug 165081
Unable to post File data in Safari 10 with a XHR POST request
https://bugs.webkit.org/show_bug.cgi?id=165081
Summary
Unable to post File data in Safari 10 with a XHR POST request
bede.bignell
Reported
2016-11-27 00:34:24 PST
Uploading an image (from a dataUrl format) using an XHR request appears to fail on iOS (10.0.2+), other browsers are working: the latest Chrome (54.0.2840.71), Firefox (50.0). The request seems to be constructed correctly in JS, but there is no actual data attached to the request. var dataUrl = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4QBMRXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAZKADAAQAAAABAAAASwAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZjs+EJ+/8AAEQgASwBkAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8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3K5rJ8m2/wCfe3/78R//ABNZ/wCvWKWjgvw/yPtH4c0W7wq6dNH/AJn/2Q=="; // create base64 encoded version of image let parts = dataUrl.split(','); let mime = parts[0].match(/:(.*?);/)[1]; let bstr = atob(parts[1]); let n = bstr.length; let u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } let blob = new window.Blob([u8arr], {type: mime}); file = new window.File([blob], file.name); // create formdata for uploading let data = new FormData(); data.append('file', file, file.name); // send the post request var xhr = new XMLHttpRequest; xhr.onload = function (oEvent) { // Uploaded. if ( oEvent.target.status == '200') { console.log('upload with XHR success'); } else { console.log('upload with XHR error'); } }; xhr.open("POST", '/upload-endpoint', false); xhr.send(data);
Attachments
test case
(1.16 KB, text/html)
2017-05-10 23:34 PDT
,
koichiro.sobue+webkit
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Alexey Proskuryakov
Comment 1
2016-11-29 12:21:50 PST
Weird! Probably a general issue with Files created from Blobs, as there doesn't seem to be anything XHR specific here. As a workaround, you can create the FormData with a Blob instead of a File: data.append('file', blob, name);
Radar WebKit Bug Importer
Comment 2
2016-12-01 12:35:28 PST
<
rdar://problem/29464619
>
koichiro.sobue+webkit
Comment 3
2017-05-10 23:31:32 PDT
When File object is created using window.File constructor, m_path won't be set.
https://github.com/WebKit/webkit/blob/master/Source/WebCore/fileapi/File.cpp#L74
This causes the following if statement to evaluate false, resulting the file being ignored.
https://github.com/WebKit/webkit/blob/master/Source/WebCore/platform/network/FormData.cpp#L226
I don't think this checking is necessary.
koichiro.sobue+webkit
Comment 4
2017-05-10 23:34:29 PDT
Created
attachment 309693
[details]
test case
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug