diff --git a/server/apps/immich/src/config/asset-upload.config.ts b/server/apps/immich/src/config/asset-upload.config.ts index fef4de210f..935012d1a3 100644 --- a/server/apps/immich/src/config/asset-upload.config.ts +++ b/server/apps/immich/src/config/asset-upload.config.ts @@ -7,6 +7,7 @@ import { existsSync, mkdirSync } from 'fs'; import { diskStorage } from 'multer'; import { extname, join } from 'path'; import sanitize from 'sanitize-filename'; +import { patchFormData } from '../utils/path-form-data.util'; export const assetUploadOption: MulterOptions = { fileFilter, @@ -55,6 +56,8 @@ function filename(req: Request, file: Express.Multer.File, cb: any) { return cb(new UnauthorizedException()); } + file.originalname = patchFormData(file.originalname); + const fileNameUUID = randomUUID(); if (file.fieldname === 'livePhotoData') { diff --git a/server/apps/immich/src/config/profile-image-upload.config.ts b/server/apps/immich/src/config/profile-image-upload.config.ts index af4255d3fb..05d9bcfc55 100644 --- a/server/apps/immich/src/config/profile-image-upload.config.ts +++ b/server/apps/immich/src/config/profile-image-upload.config.ts @@ -6,6 +6,7 @@ import { existsSync, mkdirSync } from 'fs'; import { diskStorage } from 'multer'; import { extname } from 'path'; import sanitize from 'sanitize-filename'; +import { patchFormData } from '../utils/path-form-data.util'; export const profileImageUploadOption: MulterOptions = { fileFilter, @@ -49,6 +50,8 @@ function filename(req: Request, file: Express.Multer.File, cb: any) { return cb(new UnauthorizedException()); } + file.originalname = patchFormData(file.originalname); + const userId = req.user.id; const fileName = `${userId}${extname(file.originalname)}`; diff --git a/server/apps/immich/src/utils/path-form-data.util.ts b/server/apps/immich/src/utils/path-form-data.util.ts new file mode 100644 index 0000000000..4ab7d56c50 --- /dev/null +++ b/server/apps/immich/src/utils/path-form-data.util.ts @@ -0,0 +1,3 @@ +export function patchFormData(latin1: string) { + return Buffer.from(latin1, 'latin1').toString('utf8'); +}