diff --git a/packages/nocodb/src/lib/services/public/publicData.svc.ts b/packages/nocodb/src/lib/services/public/publicData.svc.ts index 0a29b7201b..9dcfe94227 100644 --- a/packages/nocodb/src/lib/services/public/publicData.svc.ts +++ b/packages/nocodb/src/lib/services/public/publicData.svc.ts @@ -243,18 +243,25 @@ export async function dataInsert(param: { if (fieldName in fields && fields[fieldName].uidt === UITypes.Attachment) { attachments[fieldName] = attachments[fieldName] || []; - const fileName = `${nanoid(6)}_${file.originalname}`; - let url = await storageAdapter.fileCreate( + const fileName = `${nanoid(18)}${path.extname(file.originalname)}`; + + const url = await storageAdapter.fileCreate( slash(path.join('nc', 'uploads', ...filePath, fileName)), file ); + let attachmentPath; + + // if `url` is null, then it is local attachment if (!url) { - url = `${param.siteUrl}/download/${filePath.join('/')}/${fileName}`; + // then store the attachment path only + // url will be constructed in `useAttachmentCell` + attachmentPath = `download/${filePath.join('/')}/${fileName}`; } attachments[fieldName].push({ - url, + ...(url ? { url } : {}), + ...(attachmentPath ? { path: attachmentPath } : {}), title: file.originalname, mimetype: file.mimetype, size: file.size,