I can’t upload a file to the server via a form, using AngularJS and RESTFul NodeJS, as well as widgets from kendo Code on Angular:

saveBook: function (data, method) { var url = ""; if (method.toUpperCase() === 'PUT') { url = constantService.SERVER_URL + 'books/' + data._id; } else { url = constantService.SERVER_URL + 'books'; } return $http({ method: method, url: url, data: data, headers: {'Content-Type': 'application/json'} }); } 

Code on NodeJS:

 var express = require('express'), router = express.Router(), Category = require('../models/Category'), multer = require('multer'), upload = multer({dest: './uploads/'}).any(), Book = require('../models/Book'); .post(function (req, res) { upload(req, res, function (err) { if (err) { console.log(err); return; } console.log(req.file); console.log(req.files); console.log(req.body.title); console.log(JSON.stringify(req.headers)); }); 

});

console.log(req.file) and console.log(req.files) display undefined

enctype="multipart/form-data" - the form has

BookController controller:

 $scope.save = function () { bookService.saveBook($scope.model, method).success(function (data, status) { $scope.booksWindow.close(); errorService.processError(data.message, status); $scope.refreshBooksTable(); }).error(function (data, status) { errorService.processError(data.errmsg, status); }) } <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="img">Выберите обложку</label> <input id="img" type="file" kendo-upload="img" name="img" class="form-control" ng-model="model.img" style="width: 100%"/> </div> </div> </div> 
  • and how is saveBook called? - Grundy
  • BookController controller: $ scope.save = function () {bookService.saveBook ($ scope.model, method) .success (function (data, status) {$ scope.booksWindow.close (); errorService.processError (data.message, status); $ scope.refreshBooksTable ();}). error (function (data, status) {errorService.processError (data.errmsg, status);})} - El Salvadore
  • add all the necessary code directly to the question - Grundy
  • how and with what does $ scope.model fill out ? - Grundy
  • The kendoWindow widget is used there the form is placed there, all data is sent to the server only the file is not loaded. - El Salvadore

0