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