后台返回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);
}
}
添加回复
请先登陆