Lime Web Components API Documentation - v7.13.1
    Preparing search index...

    Interface FileUploadHandleBeta

    A single file upload, created by LimeFileRepository.createUpload.

    The handle is created synchronously and starts nothing until FileUploadHandle.upload is called, so it can be stored and cancelled later, for example when the user removes the file from a composer.

    import { PlatformServiceName } from '@limetech/lime-web-components';

    declare const file: File;
    declare const image: HTMLImageElement;
    declare const showProgress: (fraction: number) => void;

    async function uploadImage() {
    const files = platform.get(PlatformServiceName.LimeFileRepository);
    const handle = files.createUpload(file);

    const uploaded = await handle.upload((loaded, total) => {
    showProgress(loaded / total);
    });

    image.src = uploaded.getUrl('contents') ?? '';
    }

    void uploadImage();
    import {
    FileUploadHandle,
    PlatformServiceName,
    } from '@limetech/lime-web-components';

    declare const file: File;
    declare const removeButton: HTMLButtonElement;

    const files = platform.get(PlatformServiceName.LimeFileRepository);
    const handle: FileUploadHandle = files.createUpload(file);

    async function startUpload() {
    try {
    await handle.upload();
    } catch {
    // A cancelled or failed upload is handled by removing the file.
    }
    }

    void startUpload();

    removeButton.addEventListener('click', () => {
    handle.cancel();
    });
    interface FileUploadHandle {
        cancel(): void;
        upload(onProgress?: FileUploadProgressCallback): Promise<UploadedFile>;
    }
    Index

    Methods

    Methods

    • Beta

      Cancel the upload.

      The upload() promise rejects with a FileUploadError of type cancelled. Has no effect once the upload has finished.

      Returns void