javascript - How to upload multiple images and object data in Angular js to Spring Controller -
request multipart file angular js not getting mapped spring controller request parameter file.
my angular js code uplaod multiple images , object data looks below angular js controller:
adminservice.addimage($scope.gallery, $scope.logo.image).then(function(success) { alertservice.alert("addded successfully") $scope.back(); $scope.isloading = false; }
service js file
adminserv.addimage= function(obj, file) { var deferred = $q.defer(); var formdata = new formdata(); formdata.append("advertisementrequestjson", json.stringify(obj)); formdata.append("files", file); $http.post(app_config.api_url + 'api/saveadvertisementdetails', formdata, { transformrequest: angular.identity, headers: { 'content-type': undefined } }).then(function(data) { deferred.resolve(data); }, function(error) { deferred.reject(error); }); return deferred.promise; };
html code is
<input required name="name" ng-model="gallery.galleryname"> <input type="file" ngf-select ng-model="logo.image" ngf-max-size="20mb" name="file" accept="image/*" aria-label="logo" ngf-multiple="true">
spring controller code :
public @responsebody commonresponsedto savegallery( @requestparam(value = "file", required = false) multipartfile file, @requestparam(value = "requestjson", required = true) string requestjson){ gallerydto gallerydto = new gallerydto(); gallerydto.setmultipartfiles(file); gallerydto.setrequestjson(requestjson); return galleryservice.savegallery(gallerydto);
Comments
Post a Comment