0

I am new to angular. I have searched a lot but didn't find a way to grab the data send through Upload.upload() of ng-file-upload. Though my file is uploaded into the destination folder using muter

Here is my controlled function which is called on upload click from the view.

$scope.doUpload = function() {
Upload.upload({
      url: '/api/upload/',
      data: {'sabhaDetails': sabhaDetails},
      file: sabhaFile,
      fileName: sabhaDetails.sabha_video_name
    });
}

In my route I have:

/ annotator page. (http://localhost:1337/api/upload)
annotationRouter.route('/upload')
  .post(function(req, res) {
    **console.log(req.data);**
    upload(req, res, function(err) {
      if(err) {
        res.json({ error_code:1, err_desc:err });
        return;
      }
      res.json({ error_code:0, err_desc:null });
    })
  });

But I am getting undefined for my req.data. Is there something wrong. How to grab the send data through upload?

2 Answers 2

1

If you are using Node.js, all the form data apart from the files, should be allocated under the body key of your request object

In this case I think it should be req.body.data

The way I made it work sending everything on the data key:

Upload.upload({
      url: '/api/works/new',
      method: 'POST',
      data: {content: angular.toJson(controller.work), file: controller.thumb}
  }).

And then I can read as:

req.body.content

and the file as:

req.file.filename
Sign up to request clarification or add additional context in comments.

Comments

0

You are receiving multipart/form-data from ngf.

I don't know which server you are using, but I think you should check req.form rather than req.data or something.

Alternatively, you can use some external middleware, like this

Comments

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.