[REGRESSION] Multiple uploads not working on iOS (#2738)

* Update React Native to 0.63.4

* Fix multiple uploads not working on iOS
This commit is contained in:
Diego Mello 2020-12-23 08:49:00 -03:00 committed by GitHub
parent e6d6b83b5d
commit fec1741275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 27 deletions

View File

@ -1,46 +1,50 @@
class Upload {
constructor() {
this.xhr = new XMLHttpRequest();
this.formData = new FormData();
}
then = (callback) => {
this.xhr.onload = () => callback({ respInfo: this.xhr });
this.xhr.send(this.formData);
}
catch = (callback) => {
this.xhr.onerror = callback;
}
uploadProgress = (callback) => {
this.xhr.upload.onprogress = ({ total, loaded }) => callback(loaded, total);
}
cancel = () => {
this.xhr.abort();
return Promise.resolve();
}
}
class FileUpload { class FileUpload {
_xhr = new XMLHttpRequest();
_formData = new FormData();
fetch = (method, url, headers, data) => { fetch = (method, url, headers, data) => {
this._xhr.open(method, url); const upload = new Upload();
upload.xhr.open(method, url);
Object.keys(headers).forEach((key) => { Object.keys(headers).forEach((key) => {
this._xhr.setRequestHeader(key, headers[key]); upload.xhr.setRequestHeader(key, headers[key]);
}); });
data.forEach((item) => { data.forEach((item) => {
if (item.uri) { if (item.uri) {
this._formData.append(item.name, { upload.formData.append(item.name, {
uri: item.uri, uri: item.uri,
type: item.type, type: item.type,
name: item.filename name: item.filename
}); });
} else { } else {
this._formData.append(item.name, item.data); upload.formData.append(item.name, item.data);
} }
}); });
return this; return upload;
}
then = (callback) => {
this._xhr.onload = () => callback({ respInfo: this._xhr });
this._xhr.send(this._formData);
}
catch = (callback) => {
this._xhr.onerror = callback;
}
uploadProgress = (callback) => {
this._xhr.upload.onprogress = ({ total, loaded }) => callback(loaded, total);
}
cancel = () => {
this._xhr.abort();
return Promise.resolve();
} }
} }