Skip to content

Commit

Permalink
fix: file names with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 12, 2022
1 parent 0b9cc3b commit bfbf3d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"argon2": "^0.29.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"content-disposition": "^0.5.4",
"mime-types": "^2.1.35",
"moment": "^2.29.4",
"multer": "^1.4.5-lts.1",
Expand Down
7 changes: 6 additions & 1 deletion backend/src/file/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UseInterceptors,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import * as contentDisposition from "content-disposition";
import { Response } from "express";
import { JwtGuard } from "src/auth/guard/jwt.guard";
import { FileDownloadGuard } from "src/file/guard/fileDownload.guard";
Expand Down Expand Up @@ -41,6 +42,10 @@ export class FileController {
file: Express.Multer.File,
@Param("shareId") shareId: string
) {
// Fixes file names with special characters
file.originalname = Buffer.from(file.originalname, "latin1").toString(
"utf8"
);
return new ShareDTO().from(await this.fileService.create(file, shareId));
}

Expand Down Expand Up @@ -98,7 +103,7 @@ export class FileController {
res.set({
"Content-Type": file.metaData.mimeType,
"Content-Length": file.metaData.size,
"Content-Disposition": `attachment ; filename="${file.metaData.name}"`,
"Content-Disposition": contentDisposition(file.metaData.name),
});

return new StreamableFile(file.file);
Expand Down

0 comments on commit bfbf3d8

Please sign in to comment.