send data url to server

This commit is contained in:
waltem01 2024-02-16 07:21:03 +01:00
parent ad72d2582e
commit 8f4e669d51

View File

@ -10,6 +10,12 @@
let imageURL: string | null, lastImage: File;
let uploadData: UploadData;
async function sendImage(url: string) {
const fdata = new FormData();
fdata.append('url', url);
await post(fdata, 'upload');
}
async function fileAsDataURL(file: File, width: number, height: number): Promise<string> {
return new Promise((resolve, reject) => {
const img = new Image();
@ -73,8 +79,13 @@
{#await fileAsDataURL(lastImage, 192, 192)}
<p>Loading image data . . .</p>
<p>{uploadData.elapsed} seconds elapsed.</p>
{:then}
<p>Done!</p>
<p>{uploadData.elapsed} seconds elapsed.</p>
{:then dataUrl}
{#await sendImage(dataUrl)}
<p>Sending image . . .</p>
<p>{uploadData.elapsed} seconds elapsed.</p>
{:then}
<p>Done!</p>
<p>{uploadData.elapsed} seconds elapsed.</p>
{/await}
{/await}
{/if}