check status code of upload request
This commit is contained in:
@@ -61,8 +61,7 @@ function read_file(file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function upload_file(file, url) {
|
export function upload_file(file, url) {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log("hi");
|
|
||||||
read_file(file).then((content) => {
|
read_file(file).then((content) => {
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
@@ -71,8 +70,13 @@ export function upload_file(file, url) {
|
|||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
},
|
},
|
||||||
body: new Blob([content], { type: file.type }),
|
body: new Blob([content], { type: file.type }),
|
||||||
}).then(response => resolve(response));
|
}).then((resp) => {
|
||||||
},
|
if (resp.status >= 200 && resp.status < 300) {
|
||||||
reject => console.log(reject));
|
resolve(resp);
|
||||||
|
} else {
|
||||||
|
reject(resp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(error => reject(error));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user