From 52d27a0de69ecbb0005ab8b322a8988acf180a96 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 21 Jan 2023 13:40:15 +0800 Subject: [PATCH] feat(nocodb): add path to attachment object conditionally --- packages/nocodb/src/lib/meta/api/attachmentApis.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/lib/meta/api/attachmentApis.ts b/packages/nocodb/src/lib/meta/api/attachmentApis.ts index df6738763c..b55b2472ef 100644 --- a/packages/nocodb/src/lib/meta/api/attachmentApis.ts +++ b/packages/nocodb/src/lib/meta/api/attachmentApis.ts @@ -59,14 +59,18 @@ export async function upload(req: Request, res: Response) { file ); + let attachmentPath; + + // if `url` is null, then it is local attachment if (!url) { - url = `${(req as any).ncSiteUrl}/download/${filePath.join( - '/' - )}/${fileName}`; + // then store the attachement path only + // url will be constructued in `useAttachmentCell` + attachmentPath = `download/${filePath.join('/')}/${fileName}`; } return { - url, + ...(url ? { url } : {}), + ...(attachmentPath ? { path: attachmentPath } : {}), title: file.originalname, mimetype: file.mimetype, size: file.size,