【发布时间】:2021-03-25 02:54:48
【问题描述】:
我正在使用 Java 8 和 SpringBoot 构建一个微服务, 就是要有以下的流程-
- 将传入一个文件,名称为 GUID,没有文件扩展名。
- 另一个 xml 文件将进入,其中包含文件类型 eg/xslx
- 文件类型是从xml中抓取的
- *file 然后通过 Http POST 发送出去,正文作为文件负载 以及包含 mime 类型的标头“Content-Type”。
*支持所有 MS Office 文档类型 - https://www.askingbox.com/info/mime-types-of-microsoft-office-file-formats 那里列出了 22 种不同的 mime 类型。
我已将自定义 MessageConverter 添加到我的 RestTemplate -
MediaType mt = new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"); List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); ByteArrayHttpMessageConverter converter = new ByteArrayHttpMessageConverter(); converter.setSupportedMediaTypes(Collections.singletonList(mt)); messageConverters.add(converter); restTemplate.setMessageConverters(messageConverters);
问题是 Spring AFAIK 不支持任何这些类型,因此 MediaType.ALL 不会覆盖它们。 所以只要我添加类似的东西
application/vnd.openxmlformats-officedocument.wordprocessingml.template
作为 Content-Type Header, 春天抱怨:
No HttpMessageConverter for sun.nio.ch.ChannelInputStream and content type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
有没有人知道如何让 Spring 表现并接受 MS mime 类型:https://www.askingbox.com/info/mime-types-of-microsoft-office-file-formats
谢谢
【问题讨论】:
标签: java spring spring-boot rest ms-office