Post Multipart File inside the model - Restful Angularjs - Spring Server

I want to send via Angularjs a file (multipartFile) inside my model

this is my controller model

    $scope.modelDomain = {};
    $scope.modelDomain.id = compose.id;
    $scope.modelDomain.title = compose.title;
    $scope.modelDomain.message = compose.message;
    // a file to upload inside my model
    $scope.modelDomain.file = compose.file;

A Angular:

angular.module('SecureApp')
  .service('Publishing', function ($resource) {
    return $resource(
      'http://localhost:8080/ServerApp/rest/secure/domain', 
      {modelDomain:'@modelDomain'}, 
      { 
      save: { 
        method: 'POST', 
        params: {modelDomain:'@modelDomain'},
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined},
      } 
  });
 })

a Spring Server

@RequestMapping(value = "/rest/secure/domain", method = RequestMethod.POST)
@ResponseBody
public BufferPublishing newBuffer(@RequestParam ModelDomain modelDomain, HttpServletRequest request){
        ....
    }

server model

public class ModelDomain implements Serializable{

    private static final long serialVersionUID = 7208838545241745827L;
    Integer id;
    String title;
    String message;
    CommonsMultipartFile file;

it does not work, the server side does not infect the client call. some advice?

+4
source share

Source: https://habr.com/ru/post/1537117/


All Articles