Skip to content

Commit

Permalink
Use ObjectURL
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba committed Jan 14, 2025
1 parent 1f04721 commit 203517b
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions client/src/ura/editor/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class Uploader {
const upload: (i: number) => Promise<boolean> = (i: number) => new Promise((resolve, reject) => {
this.progressImage_.src = '';
const file = files[i];
const execUpload = () => {
const execUpload = () =>
fetch('/upload', {
method: 'POST',
body: file,
Expand All @@ -79,21 +79,15 @@ export default class Uploader {
embeds.push(resp);
this.progressBar_.value = i+1;
return (i + 1) < files.length ? upload(1 + i) : Promise.resolve(true);
}).then(resolve, reject);
};
if(file.type.startsWith('image/')){
const fr = new FileReader();
fr.onload = event => {
this.progressImage_.onload = () => execUpload();
this.progressImage_.src = event.target!.result as string;
};
fr.onerror = ev => reject(fr.error);
fr.onabort = ev => reject(fr.error);
fr.readAsDataURL(file);
});
if(file.type.startsWith('image/')) {
const url = URL.createObjectURL(file);
this.progressImage_.src = url;
execUpload().finally(() => URL.revokeObjectURL(url)).then(resolve, reject);
} else if (file.type.startsWith('video/')) {
execUpload();
execUpload().then(resolve, reject);
} else if (file.type.startsWith('audio/')) {
execUpload();
execUpload().then(resolve, reject);
}
});

Expand Down Expand Up @@ -139,4 +133,4 @@ export default class Uploader {
}
this.upload_(this.fileButton_.files);
}
}
}

0 comments on commit 203517b

Please sign in to comment.