Search code examples
node.jspostmanexpress-fileupload

Node JS REST API image upload, how do i only upload jpg files and not png?


I am using express-fileupload as my middleware and POSTMAN as my API, how do I only upload jpg images and not others file extensions?


Solution

  • You can check the mimetype and throw an error if it isn't .jpg

    For example:

    app.post('/upload', function(req, res) {
      if (req.files.image.mimetype !== "jpg") {
        throw new Error("Only supports jpg file format");
      }
    });