0

I'm creating an upload img service. My problem is that I can't seem to get the data from my endpoint.

I'm using ng-file-upload and multer

HTML

<div class="button" ngf-select ng-model="vm.uploadedImages" name="file" ngf-pattern="'image/*'" ngf-accept="'image/*'" ngf-max-size="20MB"
ngf-min-height="100" ngf-resize="{width: 100, height: 100}">Select</div>


<button class="btn btn-primary btn-raised btn-sm" ng-click="vm.test()">save</button>

CONTROLLER

vm.test = function () {
  console.log(vm.uploadedImages); // img getting the data

  Upload.upload({
    url: 'api/getTest', //webAPI exposed to upload the file
    data: { file: vm.uploadedImages } //pass file as data, should be user ng-model
  });
};

ROUTES

router.post('/getTest', function (req, res) {
    console.log('req', req.body); // getting blank value 
    res.send(req.body);
});
halfer
  • 19,824
  • 17
  • 99
  • 186
code.cycling
  • 1,246
  • 2
  • 15
  • 33
  • it seems like your path is wrong `api/getTest` in angular conttroller and node controller '/getTest' both needs to be same – Parth Raval Jan 17 '18 at 05:01
  • @ParthRaval its triggering though so i think that's not the problem – code.cycling Jan 17 '18 at 05:01
  • this will help you this is a basic answer :- https://stackoverflow.com/questions/23114374/file-uploading-with-express-4-0-req-files-undefined/47826310#47826310 – Parth Raval Jan 17 '18 at 05:03
  • If you are using `multer`, your routes should look like this. `router.post('/getTest', upload.single('file'), function (req, res) { console.log('req', req.file); // // req.file is the `file` file res.send(req.file); });` – Ashish Jan 17 '18 at 06:21

0 Answers0