[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:
parent
e6d6b83b5d
commit
fec1741275
|
@ -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 {
|
||||
_xhr = new XMLHttpRequest();
|
||||
|
||||
_formData = new FormData();
|
||||
|
||||
fetch = (method, url, headers, data) => {
|
||||
this._xhr.open(method, url);
|
||||
const upload = new Upload();
|
||||
upload.xhr.open(method, url);
|
||||
|
||||
Object.keys(headers).forEach((key) => {
|
||||
this._xhr.setRequestHeader(key, headers[key]);
|
||||
upload.xhr.setRequestHeader(key, headers[key]);
|
||||
});
|
||||
|
||||
data.forEach((item) => {
|
||||
if (item.uri) {
|
||||
this._formData.append(item.name, {
|
||||
upload.formData.append(item.name, {
|
||||
uri: item.uri,
|
||||
type: item.type,
|
||||
name: item.filename
|
||||
});
|
||||
} else {
|
||||
this._formData.append(item.name, item.data);
|
||||
upload.formData.append(item.name, item.data);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
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();
|
||||
return upload;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue