

import ]Īs you can see above, I've uploaded two files: image1.png and image2.png. Now that we have a little bit of knowledge about these new concepts, let's see how we would go about implementing them in a controller. If you were uploading multiple files with multiple different field names, you could also use the FileFieldsInterceptor. If you were just uploading a single file you would use FileInterceptor instead of FilesInterceptor. The role of the FilesInterceptor is to extract files from the incoming request and to provide it to us through the decorator (similarly to how we extract the body of a POST request using and a DTO). We can create our own interceptors if we wish to do whatever we like, but in this case, we are going to use the built-in FilesInterceptor which the package provides for us. An "interceptor" sits in the middle of this process and can listen to/modify the messages being sent. The basic use of our server involves the user making requests from the client-side to our controllers that implement GET or POST routes, and the server sending a response back to the user. The decorator allows us to "intercept" and change requests to and from the server. FilesInterceptor, and we step through the code required to handle file uploads in a NestJS controller, we are going to talk through some concepts we will be using that I haven't covered in previous NestJS tutorials. Most of my tutorials do have a focus on using Ionic with NestJS, but it does not really matter if you aren't using Ionic on the front-end. Sending Data with POST Requests to a NestJS Backend.Using Providers and HTTP Requests in a NestJS Backend.An Introduction to NestJS for Ionic Developers.If you do not already feel comfortable with creating a basic NestJS server, creating routes, and POSTing data I would recommend completing these tutorials first: This tutorial assumes that you already have a basic working knowledge of NestJS. FilesInterceptor, and Implementing the Controller.
