Browse Source

feat: use actual filename with appended random string

pull/7958/head
Pranav C 8 months ago
parent
commit
8a8f0d78bb
  1. 11
      packages/nocodb/src/services/attachments.service.ts

11
packages/nocodb/src/services/attachments.service.ts

@ -43,7 +43,9 @@ export class AttachmentsService {
param.files?.map((file) => async () => { param.files?.map((file) => async () => {
try { try {
const originalName = utf8ify(file.originalname); const originalName = utf8ify(file.originalname);
const fileName = `${nanoid(18)}${path.extname(originalName)}`; const fileName = `${path.parse(originalName).name}_${nanoid(
5,
)}${path.extname(originalName)}`;
const url = await storageAdapter.fileCreate( const url = await storageAdapter.fileCreate(
slash(path.join(destPath, fileName)), slash(path.join(destPath, fileName)),
@ -140,10 +142,11 @@ export class AttachmentsService {
param.urls?.map?.((urlMeta) => async () => { param.urls?.map?.((urlMeta) => async () => {
try { try {
const { url, fileName: _fileName } = urlMeta; const { url, fileName: _fileName } = urlMeta;
const fileNameWithExt = _fileName || url.split('/').pop();
const fileName = `${nanoid(18)}${path.extname( const fileName = `${path.parse(fileNameWithExt).name}_${nanoid(
_fileName || url.split('/').pop(), 5,
)}`; )}${path.extname(fileNameWithExt)}`;
const attachmentUrl: string | null = const attachmentUrl: string | null =
await storageAdapter.fileCreateByUrl( await storageAdapter.fileCreateByUrl(

Loading…
Cancel
Save