Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
b3f9b9ddbb |
4
pom.xml
4
pom.xml
|
|
@ -94,7 +94,9 @@
|
|||
<dependency>
|
||||
<groupId>cn.cloudowr</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>1.4.16</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/sdk-1.4.16.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -39,7 +39,7 @@ public class ACon extends AbsController{
|
|||
}
|
||||
|
||||
String key = UUID.randomUUID().toString().replace("-", "");
|
||||
UploadFileRequest uploadFileRequest = new UploadFileRequest(Config.BukketName, key);
|
||||
UploadFileRequest uploadFileRequest = new UploadFileRequest(Main.BukketName, key);
|
||||
uploadFileRequest.setUploadFile(file.getUploadPath() + File.separator + file.getFileName());
|
||||
uploadFileRequest.setTaskNum(5);
|
||||
uploadFileRequest.setPartSize(1 * 1024 * 1024);
|
||||
|
|
@ -48,7 +48,7 @@ public class ACon extends AbsController{
|
|||
uploadFileResult.getMultipartUploadResult();
|
||||
|
||||
MongoCollection<Document> collection = getCollection();
|
||||
doc.put("ossurl", Config.OssUrl + key);
|
||||
doc.put("ossurl", Main.OssUrl + key);
|
||||
doc.put("filename", file.getFileName());
|
||||
collection.insertOne(doc);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package cn.cloudowr.attach;
|
||||
|
||||
import cn.cloudowr.sdk.JQueryParameterFilter;
|
||||
|
||||
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
||||
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.jfinal.config.*;
|
||||
import com.jfinal.template.Engine;
|
||||
|
|
@ -12,14 +13,13 @@ import com.mongodb.client.MongoDatabase;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static cn.cloudowr.attach.Main.*;
|
||||
|
||||
/**
|
||||
* Created by lyf66 on 2017/2/17.
|
||||
*/
|
||||
public class Config extends JFinalConfig{
|
||||
|
||||
public static final String AccessKey = "LTAI7tcTTMuROink";
|
||||
public static final String BukketName = "cowr-attach";
|
||||
public static final String OssUrl = "http://cowr-attach.oss-cn-shenzhen.aliyuncs.com/";
|
||||
private static MongoDatabase mongoDatabase;
|
||||
private static OSSClient ossClient;
|
||||
|
||||
|
|
@ -62,13 +62,9 @@ public class Config extends JFinalConfig{
|
|||
}
|
||||
@Override
|
||||
public void afterJFinalStart() {
|
||||
MongoCredential mongoCredential = MongoCredential.createCredential("root", "admin", "CoWR1111".toCharArray());
|
||||
MongoClient mongoClient = new MongoClient(new ServerAddress("120.24.5.249", 3717), Arrays.asList(mongoCredential));
|
||||
mongoDatabase = mongoClient.getDatabase("dict");
|
||||
|
||||
String endpoint = "oss-cn-shenzhen.aliyuncs.com";
|
||||
String accessKeyId = "LTAI7tcTTMuROink";
|
||||
String accessKeySecret = "qZj94FrKmJF946eHCpNjYtEXKUS0i6";
|
||||
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
||||
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
||||
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
||||
ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
}
|
||||
|
||||
|
|
@ -76,4 +72,6 @@ public class Config extends JFinalConfig{
|
|||
public void beforeJFinalStop() {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package cn.cloudowr.attach;
|
||||
|
||||
import cn.cloudowr.sdk.FastJSONUtil;
|
||||
import cn.cloudowr.sdk.IdInterceptor;
|
||||
import cn.cloudowr.sdk.jfinal.IdInterceptor;
|
||||
import com.aliyun.oss.model.UploadFileRequest;
|
||||
import com.aliyun.oss.model.UploadFileResult;
|
||||
import com.jfinal.aop.Before;
|
||||
|
|
@ -48,7 +48,7 @@ public class Controller extends com.jfinal.core.Controller {
|
|||
}
|
||||
|
||||
String key = UUID.randomUUID().toString().replace("-", "");
|
||||
UploadFileRequest uploadFileRequest = new UploadFileRequest(Config.BukketName, key);
|
||||
UploadFileRequest uploadFileRequest = new UploadFileRequest(Main.BukketName, key);
|
||||
uploadFileRequest.setUploadFile(file.getUploadPath() + File.separator + file.getFileName());
|
||||
uploadFileRequest.setTaskNum(5);
|
||||
uploadFileRequest.setPartSize(1 * 1024 * 1024);
|
||||
|
|
@ -57,7 +57,7 @@ public class Controller extends com.jfinal.core.Controller {
|
|||
uploadFileResult.getMultipartUploadResult();
|
||||
|
||||
MongoCollection<Document> collection = Config.getMongoDatabase().getCollection("attach");
|
||||
doc.put("ossurl", Config.OssUrl + key);
|
||||
doc.put("ossurl", Main.OssUrl + key);
|
||||
doc.put("filename", file.getFileName());
|
||||
collection.insertOne(doc);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,49 @@ package cn.cloudowr.attach;
|
|||
|
||||
import com.jfinal.core.JFinal;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by lyf66 on 2017/2/16.
|
||||
*/
|
||||
public class Main {
|
||||
public static String username;
|
||||
public static String database;
|
||||
public static String password;
|
||||
public static String host;
|
||||
public static int port;
|
||||
public static String dabaseName;
|
||||
public static String endpoint ;
|
||||
public static String accessKeyId ;
|
||||
public static String accessKeySecret ;
|
||||
public static String BukketName ;
|
||||
public static String OssUrl ;
|
||||
private static int AppPort;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFinal.start("src/main/webapp", 4202, "/");
|
||||
read();
|
||||
JFinal.start("src/main/webapp", AppPort, "/");
|
||||
}
|
||||
|
||||
private static void read(){
|
||||
try{
|
||||
Properties pro = new Properties();
|
||||
pro.load(Config.class.getResourceAsStream("/config.properties"));
|
||||
username = pro.getProperty("username");
|
||||
database = pro.getProperty("database");
|
||||
password = pro.getProperty("password");
|
||||
host = pro.getProperty("host");
|
||||
port = Integer.parseInt(pro.getProperty("port"));
|
||||
dabaseName = pro.getProperty("dabaseName");
|
||||
endpoint = pro.getProperty("endpoint");
|
||||
accessKeyId = pro.getProperty("accessKeyId");
|
||||
accessKeySecret = pro.getProperty("accessKeySecret");
|
||||
BukketName = pro.getProperty("BukketName");
|
||||
OssUrl = pro.getProperty("OssUrl");
|
||||
AppPort = Integer.parseInt(pro.getProperty("AppPort"));
|
||||
}catch ( Exception e ){
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
username=root
|
||||
database=admin
|
||||
password=CoWR1111
|
||||
host=120.24.5.249
|
||||
port=3717
|
||||
dabaseName=dict
|
||||
accessKeyId=LTAI7tcTTMuROink
|
||||
BukketName=cowr-attach
|
||||
OssUrl=http://cowr-attach.oss-cn-shenzhen.aliyuncs.com/
|
||||
accessKeySecret=qZj94FrKmJF946eHCpNjYtEXKUS0i6
|
||||
endpoint=oss-cn-shenzhen.aliyuncs.com
|
||||
AppPort=4202
|
||||
Loading…
Reference in New Issue