How to send file to server use AngularJS and Spring -


According to the subject line, I want to upload / send a file using AngularJS and Spring. When I submit a file from the client that contains $ scope.file = "fileURL.jpg" , but gets the file = zero on the server, and the console returns : data = {"description": "test", "status": "disapproved"} . Below is my code:

Look at me:

  label = "control-label col-sm-4 col-xs-12" for = "file" & gt ; Please upload file: & lt; Span class = "required" & gt; * & Lt; / Span & gt; & Lt; / Labels & gt; & Lt; Div class = "col-xs-4 input-maximum control" & gt; & Lt; Input class = "inline-block" type = "file" name = "file" ng-model = "file" data-rule-required = "true" id = "file" = ".jpg, .jpeg" Gt; & Lt; / Div & gt;  

and AngularJs controller:

  var test = {description: "test", status: "disapproved"}; Var FD = new form data (); Fd.append ('data', angular.toJson (test)); Fd.append ("file", $ scope.file); $ Http ({method: 'POST', url: 'Employee Service / Employee / Data / File Upload', Header: {'Content-Type': Undefined}, Data: FD, TransformerAvailability: Angular Identity). Function data, status) {warning ("success");});  

Spring controller:

  @ResponseBody @RequestMapping (value = "/ data / file upload", method = RequestMethod.POST) public string postfile (@ RequestParam throws the MultipartFile file, @RequestParam (value = "data") object data} exception {System.out.println ("data =" + data) (value = "file", required = false) return "OK!" ; }  

on HTML:

  & lt; Input Type = "file" ng-file-select = "Select OnFile ($ files)" Accept multiple = "image / *" & gt;  

On JavaScript:

  $ scope.onFileSelect = function ($ files) {for (var i = 0; i  

On the server:

  @ResponseBody @RequestMapping (value = "/ data / fileupload", method = RequestMethod.POST) public string postfile ( MultipartFile file, @RequestParam (value = "data" object data) throws exception {System.out.println ("data =" + data); @RequestParam (value = "file", required = false); return "OK! ";}  

Comments