File Upload
Teasim handles attachment of multipart/form-data
to Context.body
by default.
import { Teasim, t } from "teasim";
const app = new Teasim()
.post("/single", ({ body: { file } }) => file, {
body: t.Object({
file: t.File(),
}),
})
.listen(8080);
File validation
You can use t.File
, and t.Files
to strictly validate files:
t.File
: validate single file as Blob
t.Files
: validate multiple files (array) as Blob[]
import { Teasim, t } from "teasim";
const app = new Teasim().post("/multiple", ({ body: { files } }) => files[0], {
body: t.Object({
files: t.Files({
type: ["image", "video"],
}),
}),
});
Validation for t.File
consists of:
- type: content type of the files using
String.includes
- minSize: minimum file size
- maxSize: maximum file size
And for t.Files
extends t.File
with:
- minItems: minimum array size of files
- maxItems: maximum array size of files