【发布时间】:2018-01-17 18:22:21
【问题描述】:
我正在编写 REST 控制器,它应该允许用户上传他们的文件。
我有课
@RestController
@RequestMapping("/profiles/{userId}/files")
public class FileController {
@PostMapping(path = "upload")
public String uploadFile(@PathVariable("userId") long userId,
@RequestParam("file") MultipartFile file) throws IOException {
//some logic here
}
但我明白了
{
"timestamp": 1502301243676,
"status": 405,
"error": "Method Not Allowed",
"message": "Method Not Allowed",
"path": "/profiles/12351/files/upload"
}
我做错了吗?没有@PathVariable 的发布请求可以正常工作,但我需要这个。
【问题讨论】:
-
你是如何调用这个资源的?
-
@RossiRobinsion 通过邮递员
-
可能需要
CSRFToken。 -
@RossiRobinsion 它看起来不像这样。我目前没有任何安全措施。
-
您能告诉我们
POSTMAN请求和标头(如果有的话)吗?
标签: spring spring-mvc spring-restcontroller http-status-code-405