【问题标题】:Handling a file upload request with Spring使用 Spring 处理文件上传请求
【发布时间】:2015-01-06 14:01:58
【问题描述】:

我正在尝试从这样的请求中提取 XML 文件:

标题:

Content-Type: multipart/form-data; boundary=MIME_boundary_314159265358979

原始:

--MIME_boundary_314159265358979
Content-disposition: attachment; filename="result"
Content-Type: text/xml
Content-Transfer-Encoding: 8bit

<?xml version="1.0" encoding="ISO-8859-1"?>
<data>
</data>

--MIME_boundary_314159265358979

我在 Spring 文档的会话 17.10.5 中发现了类似的内容 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html

但在此请求中,没有 Content-Disposition 的“名称”。 关于如何在网络服务上处理它的任何建议?

@RequestMapping(value = "/request", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE
          , consumes = "multipart/form-data")
      @ResponseBody
      @ResponseStatus(value = HttpStatus.OK)
      String handleRequest(@RequestPart MultipartFile file)

【问题讨论】:

    标签: spring spring-mvc file-upload multipartform-data


    【解决方案1】:

    你可以试试:

    @RequestMapping(value = "/request", method = RequestMethod.POST)   
    public ModelAndView dataloaderUploadFile(@RequestParam(required = true) final MultipartFile file)
    {
    String xml = new String(file.getBytes());
    .....
    }
    

    【讨论】:

    • 我之前尝试过,但它不起作用我必须处理整个请求并用我自己的方法解析它。
    猜你喜欢
    • 2020-12-07
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    相关资源
    最近更新 更多