Accepting file array
A product may have more than a single image.
Now, validation is working and we also made it more elegant. However, we should allow a product to have many images of it on the store, and not just one. So, we should make some simple adjustments in the route handler and its decorators:
Pluralize the
FileInterceptor
toFilesInterceptor
Pluralize the
@UploadedFile()
decorator to@UploadedFiles()
Change the type of
file
to an array of files
And, for correctness, let's also pluralize:
The route path, from
image
toimages
The extracted field and the variable, from
file
tofiles
The method, from
uploadImage()
touploadImages()
And lastly, also define a constant for the maximum amount of files, we'll do that in files/util/file.constants. The max amount of a product's images will be defined here.
Then, use this value in the FilesInterceptor
as the second argument. Now, no more than 5 files may be sent at once.
Commit - Accepting file array in route handler
Last updated