BetaReadonly BetacontentMIME type of the uploaded file, e.g. image/png.
Readonly BetacreatedIdentifier of the user that uploaded the file.
Readonly BetaextensionThe 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;
Readonly BetafilenameThe 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"
}
Readonly BetaidServer-assigned identifier of the uploaded file.
Readonly BetalastTime the file was last modified on the server.
Readonly BetasizeThe 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,
});
}
BetaGet 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);
}
A file that has been uploaded to the server.
Extends LimeFile, so
getUrl(type)works the same way as for files attached to limeobjects.