angularjs - Angular - file upload request, adding @RequestParam -
i want add @requestparam
http
request match spring mvc @requestparam
.
how can add file upload request:
/* @param file - file input @param uploadurl - url */ this.uploadfiletourl = function(file, uploadurl){ var fd = new formdata(); //add file formdata fd.append(file.name, file); //send request $http.post(uploadurl, fd, { transformrequest: angular.identity, headers: {'content-type': undefined} }) .success(function(result){ console.log(result); }) .error(function(err){ console.log(err); }); }
in backend error required string parameter 'filename' not present
here spring mvc controller
(only header part):
@controller @requestmapping("/file") public class fileuploadcontroller { /** * upload single file using spring controller */ @requestmapping(value = "/uploadfile", method = requestmethod.post) public @responsebody string uploadfilehandler(@requestparam("filename") string filename, @requestparam("file") multipartfile file) { //rest of function
}
so append param formdata
:
fd.append('file', file); fd.append('filename', file.name);
match @requestparam
's.
thanks.
Comments
Post a Comment