亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用Spring Rest模板+ Spring Web MVC分段上傳文件

使用Spring Rest模板+ Spring Web MVC分段上傳文件

慕的地8271018 2019-12-27 15:36:04
我正在嘗試使用帶有以下代碼的RestTemplate上傳文件。   MultiValueMap<String, Object> multipartMap = new LinkedMultiValueMap<>();   multipartMap.add("file", new ClassPathResource(file));   HttpHeaders headers = new HttpHeaders();   headers.setContentType(new MediaType("multipart", "form-data"));   HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<MultiValueMap<String, Object>>(multipartMap, headers);   System.out.println("Request for File Upload : " + request);   ResponseEntity<byte[]> result = template.get().exchange(                    contextPath.get() + path, HttpMethod.POST, request,                    byte[].class);我有MultipartResolverbean,控制器代碼是@RequestMapping(value = "/{id}/image", method = RequestMethod.POST)@ResponseStatus(HttpStatus.NO_CONTENT)@Transactional(rollbackFor = Exception.class)public byte[] setImage(@PathVariable("id") Long userId,        @RequestParam("file") MultipartFile file) throws IOException {    // Upload logic}我得到以下異常 org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'file' is not present        at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:255) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]        at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:95) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]        at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]        at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 798 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號