配置视频上传服务器映射

视频

上传之后记得重新启动comcat
// 获取文件名
        String fileName = file.getOriginalFilename();

        fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "_" + fileName;
        System.out.print("(加个时间戳,尽量避免文件名称重复)保存的文件名为: "+fileName+"
");

        //加个时间戳,尽量避免文件名称重复
        String path = "C:/upload/img/" +fileName;
        //文件绝对路径
        System.out.print("保存文件绝对路径"+path+"
");

        //创建文件路径
        File dest = new File(path);

        //判断文件是否已经存在
        if (dest.exists()) {
            return "文件已经存在";
        }

        //判断文件父目录是否存在
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdir();
        }
     try {
            //上传文件
            file.transferTo(dest); //保存文件
          
            url="http://localhost/img/"+fileName;
            return url;

        } catch (IOException e) {
            e.printStackTrace();
            return "上传失败";
        }


localhost: 指定你的服务器内网地址

通过comcat映射视频路径

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
	<Context docBase="C:uploadsp" path="/sp"/>
   
  </Host>

添加到server.xml的host下面

我的映射是  sp 
那我的访问路径就是 http://localhost:8080/sp/20220322164834_22.mp4

localhost填自己服务器内网地址

视频

马赛克是你的服务器地址

经验分享 程序员 微信小程序 职场和发展