xiongzhu 5 éve
szülő
commit
01f39c027b

+ 6 - 0
log.txt

@@ -11725,3 +11725,9 @@ Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationExce
 	... 49 more
 [2019-11-09 21:59:01] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
 [2019-11-09 22:10:41] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2021-05-25 22:57:00] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2021-05-25 22:57:37] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2021-05-25 22:57:52] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2021-05-25 23:04:49] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2021-05-25 23:05:24] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.
+[2021-05-25 23:06:18] [WARN ] - Bad pool size config, start 3 < min 5. Using 5 as start.

+ 6 - 0
pom.xml

@@ -991,6 +991,12 @@
             <artifactId>http-request</artifactId>
             <version>6.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.ksyun</groupId>
+            <artifactId>ks3-kss-java-sdk</artifactId>
+            <version>1.0.2</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 31 - 27
src/main/java/com/izouma/awesomeadmin/service/OSSFileService.java

@@ -1,28 +1,30 @@
 package com.izouma.awesomeadmin.service;
 
+import com.izouma.awesomeadmin.util.ImagesUtil;
+import com.izouma.awesomeadmin.util.PropertiesFileLoader;
+import com.ksyun.ks3.dto.CannedAccessControlList;
+import com.ksyun.ks3.dto.ObjectMetadata;
+import com.ksyun.ks3.http.HttpClientConfig;
+import com.ksyun.ks3.service.Ks3;
+import com.ksyun.ks3.service.Ks3Client;
+import com.ksyun.ks3.service.Ks3ClientConfig;
+import com.ksyun.ks3.service.request.PutObjectRequest;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Service;
+
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Random;
 
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Service;
-
-import com.aliyun.oss.OSSClient;
-import com.aliyun.oss.model.OSSObject;
-import com.aliyun.oss.model.ObjectMetadata;
-import com.aliyun.oss.model.PutObjectResult;
-import com.izouma.awesomeadmin.util.ImagesUtil;
-import com.izouma.awesomeadmin.util.PropertiesFileLoader;
-
 @Service
 public class OSSFileService {
 
     /**
      * 日志对象
      */
-    private static Logger logger = Logger.getLogger(OSSFileService.class);
+    private static       Logger logger      = Logger.getLogger(OSSFileService.class);
     private static final String projectName = PropertiesFileLoader.getProperties("projectname");
 
     public String upload(InputStream fin, String path) {
@@ -31,26 +33,27 @@ public class OSSFileService {
         }
         path = projectName + "/" + path;
 
-        String aliid = PropertiesFileLoader.getDefaultProperties("aliossid", "");
-        String alikey = PropertiesFileLoader.getDefaultProperties("aliosskey", "");
-        String aliossendpoit = PropertiesFileLoader.getDefaultProperties("aliossendpoit", "");
-        String bucketname = PropertiesFileLoader.getDefaultProperties("alibucketname", "");
-        logger.info(String.format("OSS上传:\naliid: %s\nalikey: %s\naliossendpoit: %s\nbucketname: %s\npath: %s", aliid, alikey, aliossendpoit, bucketname, path));
 
-        OSSClient client = new OSSClient(aliossendpoit, aliid, alikey);
-        OSSObject object = null;
+        Ks3ClientConfig config = new Ks3ClientConfig();
+        config.setEndpoint("ks3-cn-shanghai.ksyun.com");   //此处以北京region为例
+        config.setDomainMode(false);
+        config.setProtocol(Ks3ClientConfig.PROTOCOL.https);
+
+        config.setPathStyleAccess(false);
+        HttpClientConfig hconfig = new HttpClientConfig();
+        config.setHttpClientConfig(hconfig);
         try {
-            ObjectMetadata metadata = new ObjectMetadata();
-            metadata.setContentDisposition("inline;filename=" + path.substring(path.lastIndexOf("/") + 1));
-            client.putObject(bucketname, path, fin, metadata);
-            object = client.getObject(bucketname, path);
+            Ks3 client = new Ks3Client("AKLTwzz8bGSSRIeiu0Adw5IRTA", "OKJAHrY+bpm96y66BazNWvmUtgybRldvcOPOCnz9SxCnxT2dm7/NW5v+skiRPVyO3A==", config);
+            ObjectMetadata meta = new ObjectMetadata();
+            PutObjectRequest request = new PutObjectRequest("yqjjc", path, fin, meta);
+            request.setCannedAcl(CannedAccessControlList.PublicRead);
+            client.putObject(request);
+            logger.info("OSS上传成功");
+            System.out.println("https://ks3-cn-shanghai.ksyun.com/yqjjc/" + path);
+            return "https://ks3-cn-shanghai.ksyun.com/" + path;
         } catch (Exception r) {
             logger.error("OSS上传异常:", r);
         }
-        // 如果不设置content-length, 默认为chunked编码。
-        if (object != null) {
-            return getFullPath(path);
-        }
         return null;
     }
 
@@ -77,7 +80,8 @@ public class OSSFileService {
                 randomCode.append(Integer.toString(random.nextInt(36), 36));
             }
             try {
-                String path = String.format("images/%s-%s.jpg", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode);
+                String path = String.format("images/%s-%s.jpg", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss")
+                        .format(new Date()), randomCode);
                 return upload(ImagesUtil.GenerateImage(base64), path);
             } catch (Exception e) {
                 e.printStackTrace();

+ 0 - 38
src/main/java/com/izouma/awesomeadmin/util/ImageFileUtil.java

@@ -1,15 +1,8 @@
 package com.izouma.awesomeadmin.util;
 
-import java.io.InputStream;
-
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Service;
 
-import com.aliyun.oss.OSSClient;
-import com.aliyun.oss.model.OSSObject;
-import com.aliyun.oss.model.ObjectMetadata;
-import com.aliyun.oss.model.PutObjectResult;
-
 @Service
 public class ImageFileUtil {
 
@@ -19,37 +12,6 @@ public class ImageFileUtil {
     private static Logger logger = Logger.getLogger(ImageFileUtil.class);
 
 
-    public static String UpLoadImage(InputStream fin, String path) {
-
-        logger.info("UpLoadImage :上传照片 开始  : fin:" + fin + "; phth: " + path);
-        String aliid = PropertiesFileLoader.getDefaultProperties("aliossid", "");
-        String alikey = PropertiesFileLoader.getDefaultProperties("aliosskey", "");
-        String aliossendpoit = PropertiesFileLoader.getDefaultProperties("aliossendpoit", "");
-        String bucketname = PropertiesFileLoader.getDefaultProperties("alibucketname", "izouma");
-        OSSClient client = new OSSClient(aliossendpoit, aliid, alikey);
-        OSSObject object = null;
-        logger.info("UpLoadImage :上传照片  : aliid:" + aliid + "; alikey: " + alikey + "; aliossendpoit : " + aliossendpoit + "; bucketname:"
-                + bucketname);
-        if (path.startsWith("/")) {
-            return "invalid path";
-        }
-        @SuppressWarnings("unused")
-        PutObjectResult result = client.putObject(bucketname, path, fin, new ObjectMetadata());
-
-        try {
-            object = client.getObject(bucketname, path);
-        } catch (Exception r) {
-            logger.error("UpLoadImage: 上传照片异常 ", r);
-        }
-        // 如果不设置content-length, 默认为chunked编码。
-        if (object != null) {
-            return "file exist";
-        }
-
-        return "success";
-    }
-
-
     public static String GetRealImagePath(String Path) {
 
         if (Path == null || "".equals(Path) || Path.startsWith("images")) {

+ 1 - 1
src/main/resources/properties/jdbc.properties

@@ -3,7 +3,7 @@ jdbc.driverClassName=org.gjt.mm.mysql.Driver
 #内网
 # jdbc.url=jdbc:mysql://rm-bp1l7hk66uhffxs8h.mysql.rds.aliyuncs.com/yuanqijjc
 #外网
-jdbc.url=jdbc:mysql://rm-bp1l7hk66uhffxs8hzo.mysql.rds.aliyuncs.com/yuanqijjc
+jdbc.url=jdbc:mysql://120.92.217.252:42465/yuanqijjc
 jdbc.username=admin_yuanqi
 jdbc.password=Yuanqi@2018
 jdbc.databaseName=yuanqijjc

+ 1 - 1
src/main/resources/properties/outsidews.properties

@@ -10,4 +10,4 @@ aliImageSever=http://yuanqijjc.oss-cn-hangzhou.aliyuncs.com
 rongyunappkey=k51hidwqkci6b
 rongyunappsecret=ytH5vQEUK7DdAQ
 jwtsecret=3MgWy/pJjxHCQW2pHlQbkjomTUPRo9WhsPFjUPYZZlo=
-host=http://www.yuanqijjc.com
+host=http://www.yuanqijjc.com

+ 31 - 0
src/test/java/com/izouma/awesomeadmin/service/OSSFileServiceTest.java

@@ -0,0 +1,31 @@
+package com.izouma.awesomeadmin.service;
+
+import com.izouma.awesomeadmin.dao.CommonQueryMapper;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.GenericXmlContextLoader;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+@RunWith(value = SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/applicationContext.xml"}, loader = GenericXmlContextLoader.class)
+@Transactional
+public class OSSFileServiceTest {
+    @Autowired
+    private OSSFileService ossFileService;
+
+    @Test
+    public void upload() {
+        try {
+            ossFileService.upload(new FileInputStream("/Users/drew/Desktop/111.doc"), "test/111.doc");
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+    }
+}