diff --git a/packages/nocodb/src/services/attachments.service.ts b/packages/nocodb/src/services/attachments.service.ts index be6bbea002..42c9417de3 100644 --- a/packages/nocodb/src/services/attachments.service.ts +++ b/packages/nocodb/src/services/attachments.service.ts @@ -243,22 +243,6 @@ export class AttachmentsService { }, ); - await FileReference.insert( - { - workspace_id: RootScopes.ROOT, - base_id: RootScopes.ROOT, - }, - { - storage: storageAdapter.constructor.name, - file_url: - attachmentUrl ?? - path.join('download', filePath.join('/'), fileName), - file_size: file.size, - fk_user_id: userId, - deleted: true, // root file references are always deleted as they are not associated with any record - }, - ); - const tempMetadata: { width?: number; height?: number; @@ -292,6 +276,22 @@ export class AttachmentsService { } } + await FileReference.insert( + { + workspace_id: RootScopes.ROOT, + base_id: RootScopes.ROOT, + }, + { + storage: storageAdapter.constructor.name, + file_url: + attachmentUrl ?? + path.join('download', filePath.join('/'), fileName), + file_size: size ? parseInt(size) : urlMeta.size, + fk_user_id: userId, + deleted: true, // root file references are always deleted as they are not associated with any record + }, + ); + const attachment: AttachmentObject = { ...(attachmentUrl ? { url: attachmentUrl }