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