0
我想创建一个URI,其中MultipartFile
和表单对象(bean)都是必需的。具有@RequestPart参数的表单对象导致404
的方法用下面的代码工作:
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void create(@RequestPart MultipartFile file,
@RequestPart String form) {
// ...
}
而下面卷曲命令:
curl -X POST http://localhost/files \
-F [email protected]:\path\to\file \
-F form={"x":0,"y":0,"width":512,"height":512}
但只要我试图通过一个bean来替换字符串,我得到一个404响应。
修改后的代码,不工作,用豆:
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void create(@RequestPart MultipartFile file,
@RequestPart ClipForm form) {
// ...
}
添加每个部分的Content-Type头在卷曲似乎并没有帮助:
curl -X POST http://localhost/files \
-F [email protected]:\path\to\file;type=multipart/form-data \
-F form={"x":0,"y":0,"width":512,"height":512};type=application/json
我大概错过了一些让Spring认为请求没有映射到这个方法的东西,但是到目前为止我无法得到什么。
不应该在你的卷曲字符串中使用'Content-Type'吗? –
不,'type'用于指定多部分请求的部件的内容类型。请参见[cURL手册页](https://curl.haxx.se/docs/manpage.html#-F)。 – kagmole
在你的请求映射中你没有指定'/ files'部分 - 它应该如何映射? –