我在应提供静态 .webm 和 .mp4 文件的 Spring Boot 应用程序上遇到了问题。当我将文件放入 static
时类路径上的文件夹,应用程序以内容类型 application/octet-stream
为它们提供服务而不是video/webm
,这使得它们无法与 <video>
一起使用标签。我尝试过自定义资源处理程序,但它似乎没有提供任何设置 header 的方法。图像和其他文件工作正常。
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
最佳答案
安东·诺沃帕辛的回答成功了。这有助于:
@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);
}
}
关于spring-mvc - Spring Boot 提供内容类型错误的静态 .webm 和 .mp4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38210415/