Просмотр исходного кода

新增一个导出图片接口

zhuoning 4 лет назад
Родитель
Сommit
e4428af41a

+ 71 - 0
huimv-video/huimv-video-manager/src/main/java/com/huimv/manager/controller/ImageManagerController.java

@@ -45,6 +45,7 @@ public class ImageManagerController {
     private IImageService imageService;
     private IImageService imageService;
     @Autowired
     @Autowired
     private DateUtil dateUtil;
     private DateUtil dateUtil;
+    protected HttpServletResponse response;
 
 
     /**
     /**
      * @Method      : getLastImageAiResult
      * @Method      : getLastImageAiResult
@@ -418,4 +419,74 @@ public class ImageManagerController {
         return ImageIO.read(new FileInputStream(new File(imagePathEntity.getImgPath())));
         return ImageIO.read(new FileInputStream(new File(imagePathEntity.getImgPath())));
     }
     }
 
 
+    @Deprecated
+    @RequestMapping(value = "/downloadPicture", method = RequestMethod.GET)
+    public void downloadPicture(@RequestParam(value = "imageId",required = true) String imageId) {
+
+        // 读取
+        ImagePathEntity imagePathEntity = imageService.getOneImageDetail(imageId);
+        if(imagePathEntity == null){
+            log.error("imagePathEntity["+imagePathEntity.toString()+"]==null");
+        }
+
+        // 拼接完整图片路径。这里填写图片链接
+//        String urlPath = "";
+        // 获取图片文件后缀名
+//        String postfix = "." + StringUtils.substringAfterLast(url, ".");
+
+        // 获取当前类的所在项目路径
+//        File directory = new File("");
+//        String courseFile;
+
+        String srcPath;
+//        File srcFile = null;
+        FileInputStream fileInputStream = null;
+        InputStream fis = null;
+        OutputStream out = null;
+        try {
+//            courseFile = directory.getCanonicalPath();
+//            String fileName = "\\" + StringUtil.getUUID() + postfix;
+            String fileName = imagePathEntity.getFileName();
+            System.out.println("fileName>>"+fileName);
+            // 下载文件
+//            FileDownloadUtil.downloadHttpUrl(urlPath, courseFile, fileName);
+
+//            srcPath = courseFile + fileName;
+//            srcFile = new File(srcPath);
+            srcPath = imagePathEntity.getImgPath();
+            System.out.println("srcPath>>"+srcPath);
+            fileInputStream = new FileInputStream(srcPath);
+            fis = new BufferedInputStream(fileInputStream);
+            byte[] buffer = new byte[fis.available()];
+            fis.read(buffer);
+
+            response.setContentType("application/octet-stream");
+            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
+            out = response.getOutputStream();
+            out.write(buffer);
+            out.flush();
+            out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (fileInputStream != null) {
+                    fileInputStream.close();
+                }
+                if (fis != null) {
+                    fis.close();
+                }
+                if (out != null) {
+                    out.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        // 删除中间文件
+//        if (srcFile != null) {
+//            System.out.println(FileDownloadUtil.deleteFile(srcFile));
+//        }
+    }
+
 }
 }