diff --git a/packages/nocodb/src/helpers/stringHelpers.ts b/packages/nocodb/src/helpers/stringHelpers.ts index ac797229f5..b025d971ca 100644 --- a/packages/nocodb/src/helpers/stringHelpers.ts +++ b/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'); +} diff --git a/packages/nocodb/src/services/attachments.service.ts b/packages/nocodb/src/services/attachments.service.ts index c8e835e61f..ddc671c224 100644 --- a/packages/nocodb/src/services/attachments.service.ts +++ b/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 = []; diff --git a/packages/nocodb/src/services/public-datas.service.ts b/packages/nocodb/src/services/public-datas.service.ts index f7eba61fd8..f71a11707d 100644 --- a/packages/nocodb/src/services/public-datas.service.ts +++ b/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, }); } }