diff --git a/packages/nc-gui/components/cell/attachment/utils.ts b/packages/nc-gui/components/cell/attachment/utils.ts index 12215fb270..31bd735a48 100644 --- a/packages/nc-gui/components/cell/attachment/utils.ts +++ b/packages/nc-gui/components/cell/attachment/utils.ts @@ -8,6 +8,11 @@ import MdiFilePowerpointBox from '~icons/mdi/file-powerpoint-box' import MdiFileExcelOutline from '~icons/mdi/file-excel-outline' import IcOutlineInsertDriveFile from '~icons/ic/outline-insert-drive-file' +export const getReadableFileSize = (sizeInBytes: number) => { + const i = Math.min(Math.floor(Math.log(sizeInBytes) / Math.log(1024)), 4) + return `${(sizeInBytes / 1024 ** i).toFixed(2) * 1} ${['B', 'kB', 'MB', 'GB', 'TB'][i]}` +} + export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( (updateModelValue: (data: string | Record[]) => void) => { const { $api } = useNuxtApp() @@ -137,9 +142,9 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( // verify file size if (file?.size && file.size > attachmentMeta.maxAttachmentSize) { message.error( - `The size of ${(file as File)?.name || (file as AttachmentReqType)?.fileName} exceeds the maximum file size ${ - attachmentMeta.maxAttachmentSize - } MB.`, + `The size of ${ + (file as File)?.name || (file as AttachmentReqType)?.fileName + } exceeds the maximum file size ${getReadableFileSize(attachmentMeta.maxAttachmentSize)}.`, ) continue }