Browse Source

fix(nocodb): adopt new attachment logic

pull/5454/head
Wing-Kam Wong 2 years ago
parent
commit
cdfe81f639
  1. 15
      packages/nocodb/src/lib/services/public/publicData.svc.ts

15
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,

Loading…
Cancel
Save