gpt4 book ai didi

java - 包含文件和 JSON 对象的多部分请求

转载 作者:行者123 更新时间:2023-12-01 18:55:36 24 4
gpt4 key购买 nike

我尝试创建将获取多部分文件和 json 作为输入参数的函数。我写了这样的函数,如下:

@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<UserWithPhoto> update(@RequestHeader(value="Access-key") String accessKey,
@RequestHeader(value="Secret-key") String secretKey,
@RequestPart("user") String string,
@RequestPart("photo") MultipartFile file) throws Exception{
User user = new ObjectMapper().readValue(string, User.class);

但问题是无法测试。我像这样使用 Postman 客户端并收到错误 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided
我相信它是因为我没有设置 postman 写 enter image description here

最佳答案

您是否尝试过将 MultipartResolver 添加到 Spring MVC 配置中:

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

关于java - 包含文件和 JSON 对象的多部分请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32335250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com