angular restful springmvc 文件上传出现问题

angular restful springmvc 文件上传出现问题

问题描述:

前台代码
var fd = new FormData();
fd.append('file', file);
$http({
method: 'POST',
url: uploadUrl,
data: fd,
headers: {'Content-Type': undefined},
transformRequest: angular.identity
})
.success(function (response) {
console.log('uplaod success' + response);
}).error(function (err) {
console.log('err: ' + err);
});

后台测试代码:

@RestController
@RequestMapping("file")

@RequestMapping(value = "/fileupload", method = RequestMethod.POST)
@ResponseBody
public String onUploadFile(HttpServletRequest request, @RequestParam(value = "fd", required = false) MultipartFile file) throws IllegalStateException, IOException, RestAPIException {
return "method have been triggered";
}

报错 http 405 method not allowed 405, 求个思路?


没找到哪里有问题。。。不过可以换成get试试。。。