ReadonlyextensionThe 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;
ReadonlyfilenameThe 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"
}
Optional Readonly BetaidThe unique identifier of the file in the Lime database
import { PlatformServiceName } from '@limetech/lime-web-components';
const repository = platform.get(PlatformServiceName.LimeObjectRepository);
const contract = repository.getObject('deal', 1234)?.getFile('contract');
// The id is optional, so fall back to the filename when it is missing
const key = contract?.id ?? contract?.filename;
ReadonlysizeThe 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,
});
}
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.
The type of URL to retrieve. See LimeFileUrlType for available options.
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);
}
Represents a file attached to a LimeObject
LimeFile provides metadata and URLs for files that are stored as attachments on Lime objects. This interface is typically used when working with file properties on LimeObjects, allowing components to display file information and provide download or viewing capabilities.
Files can be accessed in different ways depending on the use case - for direct download, inline viewing, editing, or PDF conversion.
Example: Displaying files from a LimeObject