lyhzzz 1 year ago
parent
commit
6f8216b36f

+ 4 - 2
src/main/java/com/fdkankan/fusion/controller/ModelController.java

@@ -109,7 +109,7 @@ public class ModelController extends BaseController{
     @GetMapping("/downMD5")
     public void downMD5(@RequestParam(required = false) Integer modelId,
                         HttpServletResponse res, HttpServletRequest req) throws IOException {
-        OutputStream os = res.getOutputStream();
+        OutputStream os = null;
         try {
             Model model = modelService.getById(modelId);
             if(model == null){
@@ -124,8 +124,10 @@ public class ModelController extends BaseController{
             }
             File file = new File(objPath +"/"+modelId + "_hash.txt");
 
+            res.setContentType("application/octet-stream");
+            res.setHeader("Content-Disposition", "attachment; filename="+modelId + "_hash.txt");
+            os = res.getOutputStream();
             FileUtil.writeString(fileInfo.toString(),file,"UTF-8");
-
             os.write(FileUtils.readFileToByteArray(file));
             os.flush();
         } finally {

+ 7 - 1
src/main/java/com/fdkankan/fusion/controller/SceneController.java

@@ -78,7 +78,9 @@ public class SceneController extends BaseController{
     @GetMapping("/downMD5")
     public void downMD5(@RequestParam(required = false) String num,
                                HttpServletResponse res, HttpServletRequest req) throws IOException {
-        OutputStream os = res.getOutputStream();
+
+        // 设置响应头,指定文件类型和内容长度
+        OutputStream os = null;
         try {
             String sceneObjPath = String.format(FilePath.OBJ_OSS_PATH, "num")+"/data/scene.json" ;
 
@@ -91,6 +93,10 @@ public class SceneController extends BaseController{
             fileInfo.setSize(size);
             String objPath = String.format(FilePath.OBJ_LOCAL_PATH,environment , "num") ;
             File file = new File(objPath +"/"+num + "_hash.txt");
+
+            res.setContentType("application/octet-stream");
+            res.setHeader("Content-Disposition", "attachment; filename="+num + "_hash.txt");
+            os = res.getOutputStream();
             FileUtil.writeString(fileInfo.toString(),file,"UTF-8");
             os.write(FileUtils.readFileToByteArray(file));
             os.flush();