public void getFile(HttpServletResponse response, String name) {
File file = new File("C:\\Users\\shuwen\\WorkCode\\imp-backend-http\\imp-backend-http-service\\src\\main\\resources\\template\\Snipaste.png");// 视频路径
if (!file.exists()) {
throw new RuntimeException("视频文件不存在!");
}
byte[] fba = getFileByteArr(file);
OutputStream sos = null;
try {
// 如果文件类型时视频的话"Content-Type", "video/MP4"
response.setHeader("Content-Type", "image/png");
sos = response.getOutputStream();
sos.write(fba);
sos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private byte[] getFileByteArr(File file) {
byte[] buffer = null;
try {
FileInputStream fis = new FileInputStream(file);
ByteArrayOu
SpringBoot读取本地图片和视频回显到浏览器中
于 2022-12-02 19:24:17 首次发布