make read file and upload separate js functions
This commit is contained in:
@@ -49,7 +49,7 @@ export function get_files_data_transfer_items(data_transfer_items) {
|
||||
return getFilesDataTransferItems(data_transfer_items);
|
||||
}
|
||||
|
||||
function read_file(file) {
|
||||
export function read_file(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
@@ -60,23 +60,21 @@ function read_file(file) {
|
||||
});
|
||||
}
|
||||
|
||||
export function upload_file(file, url) {
|
||||
export function upload(content, content_type, url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
read_file(file).then((content) => {
|
||||
fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
body: new Blob([content], { type: file.type }),
|
||||
}).then((resp) => {
|
||||
if (resp.status >= 200 && resp.status < 300) {
|
||||
resolve(resp);
|
||||
} else {
|
||||
reject(resp);
|
||||
}
|
||||
});
|
||||
}).catch(error => reject(error));
|
||||
fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
body: new Blob([content], { type: content_type }),
|
||||
}).then((resp) => {
|
||||
if (resp.status >= 200 && resp.status < 300) {
|
||||
resolve(resp);
|
||||
} else {
|
||||
reject(resp);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user