Browse Source

Merge pull request #6824 from nocodb/fix/attachment-original-name

fix(nocodb): attachment original name
pull/6829/head
Raju Udava 1 year ago committed by GitHub
parent
commit
80a20a111a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      packages/nocodb/src/helpers/stringHelpers.ts
  2. 9
      packages/nocodb/src/services/attachments.service.ts
  3. 9
      packages/nocodb/src/services/public-datas.service.ts

4
packages/nocodb/src/helpers/stringHelpers.ts

@ -3,3 +3,7 @@ import crypto from 'crypto';
export function randomTokenString(): string {
return crypto.randomBytes(40).toString('hex');
}
export function utf8ify(str: string): string {
return Buffer.from(str, 'latin1').toString('utf8');
}

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

@ -8,6 +8,7 @@ import NcPluginMgrv2 from '~/helpers/NcPluginMgrv2';
import Local from '~/plugins/storage/Local';
import mimetypes, { mimeIcons } from '~/utils/mimeTypes';
import { PresignedUrl } from '~/models';
import { utf8ify } from '~/helpers/stringHelpers';
@Injectable()
export class AttachmentsService {
@ -28,7 +29,8 @@ export class AttachmentsService {
const attachments = await Promise.all(
param.files?.map(async (file: any) => {
const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
const originalName = utf8ify(file.originalname);
const fileName = `${nanoid(18)}${path.extname(originalName)}`;
const url = await storageAdapter.fileCreate(
slash(path.join(destPath, fileName)),
@ -46,11 +48,10 @@ export class AttachmentsService {
signedUrl?: string;
} = {
...(url ? { url } : {}),
title: file.originalname,
title: originalName,
mimetype: file.mimetype,
size: file.size,
icon:
mimeIcons[path.extname(file.originalname).slice(1)] || undefined,
icon: mimeIcons[path.extname(originalName).slice(1)] || undefined,
};
const promises = [];

9
packages/nocodb/src/services/public-datas.service.ts

@ -14,6 +14,7 @@ import { getColumnByIdOrName } from '~/modules/datas/helpers';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { mimeIcons } from '~/utils/mimeTypes';
import { Column, Model, Source, View } from '~/models';
import { utf8ify } from '~/helpers/stringHelpers';
// todo: move to utils
export function sanitizeUrlPath(paths) {
@ -319,7 +320,8 @@ export class PublicDatasService {
fields[fieldName].uidt === UITypes.Attachment
) {
attachments[fieldName] = attachments[fieldName] || [];
const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
const originalName = utf8ify(file.originalname);
const fileName = `${nanoid(18)}${path.extname(originalName)}`;
const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)),
@ -337,11 +339,10 @@ export class PublicDatasService {
attachments[fieldName].push({
...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname,
title: originalName,
mimetype: file.mimetype,
size: file.size,
icon:
mimeIcons[path.extname(file.originalname).slice(1)] || undefined,
icon: mimeIcons[path.extname(originalName).slice(1)] || undefined,
});
}
}

Loading…
Cancel
Save