0

I am implementing this solution for uploading files to the server: File Upload with Angular2 to Rest API

My question is how do I access the formData items in my server-side POST method?

Code:

    router.post('/test', function(req, res) {
        // Access the formData object sent from the client
        // Do stuff...
    }

Thanks!

Community
  • 1
  • 1

1 Answers1

0

Use below code :-

 router.post('/test', function(req, res) {
     let formidable = require('formidable'); 
     let form = new formidable.IncomingForm(); 
     form.parse(req, function(err, fields, files) {
          // fields will get all fields
          if(files.file && files.file.name){ 
               //file your uploaded file
          }
     });
  });
Abhay
  • 6,410
  • 4
  • 26
  • 34