he2802 %!s(int64=2) %!d(string=hai) anos
pai
achega
ca0dbf9d77

+ 16 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/alioss/OssController.java

@@ -18,6 +18,8 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
 import java.util.Map;
 
 /**
@@ -70,4 +72,18 @@ public class OssController extends BaseController {
         return AjaxResult.success("返回图片路径",result);
     }
 
+    @ApiOperation("上传file图片")
+    @PostMapping("/uploadTest")
+    public AjaxResult<String> uploadTest() throws Exception {
+        InputStream in = ossService.getStreamByObject("oss/images/avatar/114/1315/1686203595404_1371903125");
+        FileOutputStream fos = new FileOutputStream("D:\\testfile\\b.jpg");
+        byte[] b = new byte[1024];
+        while ((in.read(b)) != -1) {
+            fos.write(b);// 写入数据
+        }
+        in.close();
+        fos.close();// 保存数据
+        return AjaxResult.success("返回图片路径","");
+    }
+
 }

+ 2 - 3
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -148,11 +148,10 @@ public class CommonController extends BaseController {
             response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
             FileUtils.setAttachmentResponseHeader(response, realFileName);
             FileUtils.writeBytes(filePath, response.getOutputStream());
-           /* if (delete)
+            if (delete)
             {
                 FileUtils.deleteFile(filePath);
-            }*/
-            FileUtils.deleteFile(filePath);
+            }
         } catch (Exception e) {
             log.error("下载文件失败", e);
         }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/service/OssService.java

@@ -33,4 +33,6 @@ public interface OssService {
     void zipCommonDownload(List<String> fileList, ZipOutputStream zipOut, String dir);
 
     void zipWisdomDownload(List<FileBean> list, ZipOutputStream outStream);
+
+    InputStream getStreamByObject(String filePath) throws Exception;
 }

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/alioss/service/impl/OssServiceImpl.java

@@ -337,6 +337,7 @@ public class OssServiceImpl implements OssService {
         }
     }
 
+    @Override
     public InputStream getStreamByObject(String filePath) throws Exception {
             OSSObject ossObject = ossClient.getObject(ALIYUN_OSS_BUCKET_NAME, filePath);
             return ossObject.getObjectContent();