【问题标题】:Spring Boot serving static .webm and .mp4 files with wrong content typeSpring Boot 提供内容类型错误的静态 .webm 和 .mp4 文件
【发布时间】:2016-11-07 16:52:04
【问题描述】:

我的 Spring Boot 应用程序应该提供静态 .webm 和 .mp4 文件时遇到问题。当我将文件放在类路径上的 static 文件夹中时,应用程序为它们提供内容类型 application/octet-stream 而不是 video/webm,这使得它们无法与 <video> 标记一起使用。我试过自定义资源处理程序,但它似乎没有提供任何设置标题的方法。图像和其他文件工作正常。

Spring Boot 输出:

$ curl -s -D - localhost:8080/CmMs.webm -o /dev/null
HTTP/1.1 200
Last-Modified: Tue, 05 Jul 2016 18:08:41 GMT
Accept-Ranges: bytes
Content-Type: application/octet-stream
Content-Length: 648708
Date: Tue, 05 Jul 2016 18:22:40 GMT

输出应该是这样的

$ curl -s -D - http://webm.land/media/CmMs.webm -o /dev/null
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Tue, 05 Jul 2016 18:23:21 GMT
Content-Type: video/webm
Content-Length: 648708
Last-Modified: Tue, 05 Jul 2016 17:42:08 GMT
Connection: keep-alive
Accept-Ranges: bytes

【问题讨论】:

标签: spring-mvc video spring-boot content-type static-content


【解决方案1】:

Anton Novopashin 的回答成功了。这有帮助:

@Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {

    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
        mappings.add("webm", "video/webm");
        mappings.add("mp4", "video/mp4");
        container.setMimeMappings(mappings);
    }
}

【讨论】:

    猜你喜欢
    • 2016-07-14
    • 2015-09-21
    • 2019-03-30
    • 1970-01-01
    • 2015-06-21
    • 2019-07-11
    • 2019-09-20
    • 2021-10-29
    相关资源
    最近更新 更多