I want to add @RequestParam
to my http
request so it will match spring MVC @RequestParam
.
How can I add this to my file upload request:
/* @param file - file from input @param uploadUrl - url */ this.uploadFileToUrl = function(file, uploadUrl){ var fd = new FormData(); //add file to 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 my backend the error is Required String parameter 'filename' is not present
Here is my Spring MVC controller
(only the 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 the function
}
$http
orFormData
and tried to add the parameters as described. What problems did you experience?