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

    Interface UploadedFileBeta

    A file that has been uploaded to the server.

    Extends LimeFile, so getUrl(type) works the same way as for files attached to limeobjects.

    interface UploadedFile {
        contentType: string;
        createdBy: number;
        extension: string;
        filename: string;
        id: number;
        lastModified: Date;
        size: number;
        getUrl(type: LimeFileUrlType): string | undefined;
    }

    Hierarchy (View Summary)

    Index

    Properties

    contentType: string

    MIME type of the uploaded file, e.g. image/png.

    createdBy: number

    Identifier of the user that uploaded the file.

    extension: string

    The file extension without the leading dot

    The extension is extracted from the filename and provided separately for convenience when filtering or categorizing files.

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

    const IMAGE_EXTENSIONS = new Set(['jpg', 'jpeg', 'png', 'gif']);

    function isImage(file: LimeFile): boolean {
    return IMAGE_EXTENSIONS.has(file.extension.toLowerCase());
    }

    const repository = platform.get(PlatformServiceName.LimeObjectRepository);
    const attachment = repository.getObject('deal', 1234)?.getFile('drawing');

    const imageUrl =
    attachment && isImage(attachment) ? attachment.getUrl('view') : undefined;
    filename: string

    The name of the file including its extension

    This is the original filename as it was uploaded or created, including the file extension.

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

    const logger = createLogger('my-component');
    const repository = platform.get(PlatformServiceName.LimeObjectRepository);
    const contract = repository.getObject('deal', 1234)?.getFile('contract');

    if (contract) {
    logger.info(contract.filename); // "annual-report.pdf"
    }
    id: number

    Server-assigned identifier of the uploaded file.

    lastModified: Date

    Time the file was last modified on the server.

    size: number

    The size of the file in bytes

    Use this to display file size information to users or to implement file size validation.

    import type { LimeFile } from '@limetech/lime-web-components';
    import {
    PlatformServiceName,
    createLogger,
    } from '@limetech/lime-web-components';

    const logger = createLogger('my-component');

    function formatSize(file: LimeFile): string {
    const megabytes = file.size / (1024 * 1024);

    return `${megabytes.toFixed(2)} MB`;
    }

    const repository = platform.get(PlatformServiceName.LimeObjectRepository);
    const contract = repository.getObject('deal', 1234)?.getFile('contract');

    if (contract) {
    logger.info(`File size: ${formatSize(contract)}`);
    }
    import {
    PlatformServiceName,
    createLogger,
    } from '@limetech/lime-web-components';

    const MAX_SIZE = 10 * 1024 * 1024;

    const logger = createLogger('my-component');
    const repository = platform.get(PlatformServiceName.LimeObjectRepository);
    const contract = repository.getObject('deal', 1234)?.getFile('contract');

    if (contract && contract.size > MAX_SIZE) {
    logger.error('File too large', undefined, {
    filename: contract.filename,
    size: contract.size,
    max: MAX_SIZE,
    });
    }

    Methods

    • Beta

      Get a URL for accessing the file in different ways

      Different URL types are available depending on how you want to access the file. Some URL types may return undefined if not supported for the specific file type.

      Parameters

      Returns string | undefined

      The URL as a string, or undefined if the URL type is not available for this file.

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

      // A pdf url only exists when conversion is available for the file type
      function getPreviewUrl(file: LimeFile): string | undefined {
      return file.getUrl('pdf') ?? file.getUrl('view');
      }

      const repository = platform.get(PlatformServiceName.LimeObjectRepository);
      const contract = repository.getObject('deal', 1234)?.getFile('contract');
      const previewUrl = contract && getPreviewUrl(contract);

      if (previewUrl) {
      window.open(previewUrl);
      }