Skip to content
This repository was archived by the owner on Jun 29, 2025. It is now read-only.

Commit bfbf3d8

Browse files
committed
fix: file names with special characters
1 parent 0b9cc3b commit bfbf3d8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

backend/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"argon2": "^0.29.1",
2222
"class-transformer": "^0.5.1",
2323
"class-validator": "^0.13.2",
24+
"content-disposition": "^0.5.4",
2425
"mime-types": "^2.1.35",
2526
"moment": "^2.29.4",
2627
"multer": "^1.4.5-lts.1",

backend/src/file/file.controller.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
UseInterceptors,
1212
} from "@nestjs/common";
1313
import { FileInterceptor } from "@nestjs/platform-express";
14+
import * as contentDisposition from "content-disposition";
1415
import { Response } from "express";
1516
import { JwtGuard } from "src/auth/guard/jwt.guard";
1617
import { FileDownloadGuard } from "src/file/guard/fileDownload.guard";
@@ -41,6 +42,10 @@ export class FileController {
4142
file: Express.Multer.File,
4243
@Param("shareId") shareId: string
4344
) {
45+
// Fixes file names with special characters
46+
file.originalname = Buffer.from(file.originalname, "latin1").toString(
47+
"utf8"
48+
);
4449
return new ShareDTO().from(await this.fileService.create(file, shareId));
4550
}
4651

@@ -98,7 +103,7 @@ export class FileController {
98103
res.set({
99104
"Content-Type": file.metaData.mimeType,
100105
"Content-Length": file.metaData.size,
101-
"Content-Disposition": `attachment ; filename="${file.metaData.name}"`,
106+
"Content-Disposition": contentDisposition(file.metaData.name),
102107
});
103108

104109
return new StreamableFile(file.file);

0 commit comments

Comments
 (0)