Questions & Answers

How can I handle file downloads?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

To handle file downloads, you can use the HttpResponse.sendFile method. Here's an example:

import { HttpRequest, HttpResponse } from '@deepkit/http';

router.get('/download', (request: HttpRequest, response: HttpResponse) => {
  response.sendFile('/path/to/file.pdf', 'application/pdf', 'file.pdf');
});

In this example, the file at /path/to/file.pdf will be sent as a download with the filename file.pdf and the application/pdf content type.