【问题标题】:Apache camel Multipart issueApache骆驼多部分问题
【发布时间】:2018-12-19 00:55:37
【问题描述】:

我正在尝试通过 angular 4 as 上传带有 pdf 文件的表单

请求是一个多部分/表单数据请求

我正在使用spring boot,apache camel-servlet,我的路由为

 rest("/notice").description("Upload Multiple Report via camel and netty")
                        .post().route().unmarshal().mimeMultipart()
                        .to("direct:uploadReportProcessor");

在我的处理器中我有

Map<String, DataHandler> attachments = exchange.getIn().getAttachments();

然后我尝试写入如下文件:

    byte[] bytes = StreamUtils.copyToByteArray(dh.getInputStream());

Path path = Paths.get("C:\\temp\\" + dh.getName());
Files.write(path, bytes);

无论我尝试什么,文件总是损坏。无法在 Acrobat 阅读器中打开。

【问题讨论】:

    标签: apache-camel multipartform-data


    【解决方案1】:

    这可能是编码问题。

    Map<String, DataHandler> attachments = exchange.getIn().getAttachments();
    
    String charsetPartStr = attachments.get("content").getContentType();
    Files.write(path, bytes, StandardOpenOption.APPEND,  Charset.forName(charsetPartStr));
    

    保留部件的媒体类型,以便在编写文件时使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-03
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多