1

Doing a post with multer, I want to send the error message from nodejs backend with

var storage =   multer.diskStorage({
   destination: function (req, file, cb) {
     cb(null, '../uploads');
   },
   filename: function (req, file, cb) {
     cb(null,  file.originalname + '-' + Date.now());
   }
});

router.post('/upload', function(req, res){
            upload(req, res, function(err) {
            if(err){ 
                        res.json({ Status : false, message : err})
                        }else{ 
                        res.json({ Status : true, message : 'Success'})
               }
        })
    })

to the angular controller

$http({
        method:'POST',
        url:'/upload'
        }).then(function successCallback(response) {
          if(response.data.Status){ 
              console.log(response.data.message);
          }
          else{ 
              console.log(response.data.message); 
          }
      })

to show the backend success or error in the frontend console. But it only opens an empty page with {"Status":true,"message":"Success"} html:

<form enctype   =  "multipart/form-data"
      action    =  "/upload"
      method    =  "POST">

Select File:

<input type="file" name="file" >
<p></p>
<input type="submit" value="Upload File" name="submit" class="btn btn-primary">

</form>

How can I fix this?

10
  • where is your upload function? Commented Sep 28, 2016 at 9:23
  • @abdulbarik edited it above. Doing my upload with multer. Commented Sep 28, 2016 at 9:26
  • what are you getting in response.data in angular side? always same message? Commented Sep 28, 2016 at 9:28
  • Please share your upload function or print that err in callback Commented Sep 28, 2016 at 9:29
  • I want to get the data from the backend. To show in the frontend if the upload worked. Commented Sep 28, 2016 at 9:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.