You can handle file uploads using the UploadedFile
type and the HttpBody
type. The UploadedFile
type represents an uploaded file and provides information about the file, such as its size, name, type, and path. The HttpBody
type allows you to receive and validate the uploaded file as part of the request body. Here's an example:
import { HttpBody, UploadedFile } from '@deepkit/http'; class FileUpload { file!: UploadedFile; } router.post('/upload', (body: HttpBody<FileUpload>) => { const uploadedFile = body.file; // Handle the uploaded file });
You can access the properties of the UploadedFile
object, such as size
, name
, type
, and path
, to perform further processing or storage of the uploaded file.
An example HTML form for this route would look like this:
<form action="/upload" method="post" enctype="multipart/form-data"> <input type="file" name="file"> <input type="submit" value="Upload"> </form>