Skip to content

Commit 58eaf8d

Browse files
author
Eamonn McEvoy
committed
docs(streaming-files): show how to set content-type and content-disposition in the StreamableFile example.
1 parent f1ff842 commit 58eaf8d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

content/techniques/streaming-files.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Fastify, by default, can support sending files without needing to call `stream.p
3131

3232
You can find a simple example of returning the `package.json` as a file instead of a JSON below, but the idea extends out naturally to images, documents, and any other file type.
3333

34+
> info **hint** If the @Response parameter is present, it must have `{ passthrough: true }`.
35+
3436
```ts
3537
import { Controller, Get, StreamableFile } from '@nestjs/common';
3638
import { createReadStream } from 'fs';
@@ -39,8 +41,13 @@ import { join } from 'path';
3941
@Controller('file')
4042
export class FileController {
4143
@Get()
44+
@Response({ passthrough: true }) res,
4245
getFile(): StreamableFile {
4346
const file = createReadStream(join(process.cwd(), 'package.json'));
47+
res.set({
48+
'Content-Type': 'application/json',
49+
'Content-Disposition': 'attachment; filename="package.json"',
50+
});
4451
return new StreamableFile(file);
4552
}
4653
}

0 commit comments

Comments
 (0)