Streaming Files — Techniques · NestJS

Send bytes, not JSON: stream a file from disk with StreamableFile, declare its type and download name three ways, refuse a missing file before streaming, and export the cats as a CSV built in memory.

What you will learn

Read the theory for Streaming Files

All Techniques lessons

All NestJS courses

loading types…

What you'll learn

  • Return a file as a StreamableFile from a read stream or a buffer, and explain why not to pipe to the response yourself
  • Set Content-Type and Content-Disposition with @Header, res.set() and the StreamableFile options
  • Refuse a missing file with a 404 before streaming starts