TypedFormData.Body() is a request body decorator function for the
multipart/form-data content type. It automatically casts property type
following its DTO definition, and performs the type validation too.
Also, TypedFormData.Body() is much easier and type safer than
@nest.UploadFile(). If you're considering the SDK
library generation, only
TypedFormData.Body() can do it. Therefore, I recommend you to use
TypedFormData.Body() instead of the @nest.UploadFile() function.
For reference, target type T must follow such restriction. Of course, if
actual form-data values are different with their promised type T,
BadRequestException error (status code: 400) would be thrown.
Type T must be an object type
Do not allow dynamic property
Only boolean, bigint, number, string, Blob, File or their array
types are allowed
By the way, union type never be not allowed
By the way, if you're using fastify, you have to setup fastify-multer and
configure like below when composing the NestJS application. If you don't do
that, @TypedFormData.Body() will not work properly, and throw 500 internal
server error when Blob or File type being utilized.
Type safe multipart/form-data decorator.
TypedFormData.Body()is a request body decorator function for themultipart/form-datacontent type. It automatically casts property type following its DTO definition, and performs the type validation too.Also,
TypedFormData.Body()is much easier and type safer than@nest.UploadFile(). If you're considering the SDK library generation, onlyTypedFormData.Body()can do it. Therefore, I recommend you to useTypedFormData.Body()instead of the@nest.UploadFile()function.For reference, target type
Tmust follow such restriction. Of course, if actual form-data values are different with their promised typeT,BadRequestExceptionerror (status code: 400) would be thrown.Tmust be an object typeboolean,bigint,number,string,Blob,Fileor their array types are allowedBy the way, if you're using
fastify, you have to setupfastify-multerand configure like below when composing the NestJS application. If you don't do that,@TypedFormData.Body()will not work properly, and throw 500 internal server error whenBloborFiletype being utilized.Author
Jeongho Nam - https://github.com/samchon
Todo
Change to ReadableStream through configuring storage engine of multer