.war 文件太大 (600mb) 因为有视频

.war file is too big (600mb) because of videos

我在 src/resources/static 中有总共 540mb 的小视频。对于 .war 文件来说问题太大了吗?我现在将其部署到 tomcat。如果这是一个问题,我该如何解决这个问题?因为我无法在 Chrome 播放来自 javascript(使用 file:///)的本地视频。因此,我必须将它们放在项目目录中。

您可以将视频移出到服务器上的单独位置:

Simplest way to serve static data from outside the application server in a Java web application

或者您可以将它们托管在其他服务(AWS S3?)上并提供一个端点来代理它们

我的解决方案:

package com.youtalkwesign.controller;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class VideoController {

@GetMapping("sign-videos/{word}")
protected void doGet(@PathVariable String word, HttpServletResponse response) throws IOException {
    File file = new File("home/sign-videos/" + word + ".mp4"); // TODO: D:/sign-videos/ or home/sign-videos/
    response.setHeader("Content-Type", "video/mp4");
    response.setHeader("Content-Length", String.valueOf(file.length()));
    response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
    Files.copy(file.toPath(), response.getOutputStream());
}
}