NutzCN Logo
问答 后台返回mp4格式的图片预览黑屏
发布于 1724天前 作者 qq_a96bd60c 1438 次浏览 复制 上一个帖子 下一个帖子
标签:

后台返回mp4格式的图片,前台通过h5 video标签预览黑屏,同样的写法,springboot没问题,是不是nutz哪里配置不对

5 回复
@At("/downloadItemImg")
    @Ok("viod")
    public void downloadItemImg( HttpServletResponse response,HttpServletRequest request) {
        try {
             File file=new File("C:\\Users\\Administrator\\Desktop\\网点视频\\东善视频.mp4");
           response.setContentType("video/mp4");
            OutputStream os=response.getOutputStream();
            InputStream is=new FileInputStream(file);
            byte[] b=new byte[1024];
            int total=0;
            int length;
            while((length=is.read(b))!=-1){
                os.write(b,0,length);
                total+=length;
            }
            System.out.println(total);
        }  catch (IOException e) {
            e.printStackTrace();

        }
    }
Spring这么写没问题
@RequestMapping("/download")
	public void download(HttpServletRequest request,HttpServletResponse response) throws IOException {
		File file=new File("D:\\test\\东善视频.mp4");
		FileInputStream is=new FileInputStream(file);
		response.setContentType("video/mp4");
		OutputStream os=response.getOutputStream();
		byte[] b=new byte[1024];
		int length=0;
		while((length=is.read(b))!=-1){
			os.write(b,0,length);
		}
	}

其实2行就能写完

@Ok("raw:video/mp4")
    public void downloadItemImg( HttpServletResponse response,HttpServletRequest request) {
        return new File("C:\\Users\\Administrator\\Desktop\\网点视频\\东善视频.mp4");

但你的代码看上去是等价的,看看服务器响应的header有什么差异吧

好的,我试试,谢谢大神

添加回复
请先登陆
回到顶部