he2802 2 anos atrás
pai
commit
7463d1bbc8

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

@@ -23,6 +23,8 @@ public interface OssService {
 
     String upload(OssRequest base) throws Exception;
 
+    String uploadWithPath(OssRequest base,String path) throws Exception;
+
     String uploadInputStream(InputStream inputStream,Integer imageStatus) throws Exception;
 
     String uploadBase64(String fileStr,OssRequest ossRequest);

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

@@ -261,6 +261,23 @@ public class OssServiceImpl implements OssService {
         }
     }
 
+    @Override
+    public String uploadWithPath(OssRequest base, String path) throws Exception {
+        try {
+            //获取上传文件输入流
+            InputStream inputStream = base.getFile().getInputStream();
+            String originalFilename = base.getFile().getOriginalFilename();
+            
+            PutObjectResult putObjectResult = ossClient.putObject(ALIYUN_OSS_BUCKET_NAME, path, inputStream);
+            // 关闭OSSClient。
+            //ossClient.shutdown();
+            return path;
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new IllegalStateException("上传失败");
+        }
+    }
+
     @Override
     public String uploadInputStream(InputStream inputStream, Integer imageStatus) throws Exception {
         try {