0

我正在尝试将 JSON 实体和图像发布到我的 Web 服务。但是我无法让它工作。最后一个错误是请求不是多部分请求。

@RequestMapping(method = RequestMethod.POST)
public ResponseEntity savePerson(@RequestPart("data") final PersonResource personResource, @RequestPart("image") MultipartFile imageFile) { ... }

卷曲

$ curl -H "Content-Type: application/json" -X POST -F 'data={"name":"Tes
t"}' -F "image=@C:\Users\LuckyLuke\Downloads\test.jpg;type=image/jpg" localhost:8080/myapp/persons

我误解了@RequestPart注释的用法吗?请求错了吗?

4

1 回答 1

1

As far as I can see you are using @RequestMapping in a proper way. My guess is that you are geting error since you are enforcing application/json content type (-H "Content-Type: application/json"). Try to run your program without that header (-F option should take care of setting multipart/form-data request).

于 2013-04-24T20:32:30.317 回答