Browse Source

fix(nocodb): adopt new attachment logic

pull/5454/head
Wing-Kam Wong 1 year 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) { if (fieldName in fields && fields[fieldName].uidt === UITypes.Attachment) {
attachments[fieldName] = attachments[fieldName] || []; attachments[fieldName] = attachments[fieldName] || [];
const fileName = `${nanoid(6)}_${file.originalname}`; const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
let url = await storageAdapter.fileCreate(
const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)), slash(path.join('nc', 'uploads', ...filePath, fileName)),
file file
); );
let attachmentPath;
// if `url` is null, then it is local attachment
if (!url) { 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({ attachments[fieldName].push({
url, ...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname, title: file.originalname,
mimetype: file.mimetype, mimetype: file.mimetype,
size: file.size, size: file.size,

Loading…
Cancel
Save