image url only

This commit is contained in:
waltem01 2024-02-21 08:20:24 +01:00
parent 16d426c23b
commit f6316ea142

View File

@ -22,7 +22,7 @@
h: number;
}
let imageURL: string | null, lastImage: File;
let imageURL: string | null;
let uploadData: UploadData, matrix: Matrix;
let uploadStarted = false,
submitData: SubmitData;
@ -59,7 +59,7 @@
if (!mdata.success) alert(`Error while processing '${endpoint}'!`);
}
async function fileAsDataURL(file: File, data: SubmitData): Promise<string> {
async function fileAsDataURL(data: SubmitData): Promise<string> {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
@ -79,9 +79,8 @@
};
img.onerror = reject;
// Create an object URL for the file and set it as the image source
const objectURL = URL.createObjectURL(file);
img.src = objectURL;
// Load image by assigning url
img.src = imageURL!;
});
}
@ -98,8 +97,7 @@
const file = input?.files?.[0];
if (!file) return;
// Load image data and file
lastImage = file;
// Load image data from file
imageURL = URL.createObjectURL(file);
}
@ -222,8 +220,9 @@
<img class="mt-5 block ml-auto mr-auto" src={imageURL} alt="User uploaded" />
{/if}
</form>
{#if uploadStarted}
{#await fileAsDataURL(lastImage, submitData)}
{#await fileAsDataURL(submitData)}
<p>Loading image data . . .</p>
<p>{uploadData.elapsed} seconds elapsed.</p>
{:then dataUrl}