From 825771c3ae9fbbc92f6b550cf0e95eac2a3b0aac Mon Sep 17 00:00:00 2001 From: shuzheng <469741414@qq.com> Date: Mon, 15 May 2017 21:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0aliyun-oss=E6=BC=94=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project-bootstrap/ngrok.bat | 2 +- .../oss/web/controller/DemoController.java | 21 ++++++++++-- .../oss/web/service/AliyunOssService.java | 3 +- .../src/main/resources/config.properties | 5 ++- .../main/resources/profiles/dev.properties | 5 ++- .../main/resources/profiles/prod.properties | 5 ++- .../main/resources/profiles/test.properties | 5 ++- .../src/main/resources/springMVC-servlet.xml | 32 ++++++++++++++++--- .../resources/zheng-oss-client.properties | 2 ++ 9 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 zheng-oss/zheng-oss-web/src/main/resources/zheng-oss-client.properties diff --git a/project-bootstrap/ngrok.bat b/project-bootstrap/ngrok.bat index 7de1ef6a..35d71917 100644 --- a/project-bootstrap/ngrok.bat +++ b/project-bootstrap/ngrok.bat @@ -1 +1 @@ -start ngrok/ngrok -config=ngrok/ngrok.cfg -subdomain shuzheng 80 \ No newline at end of file +start ngrok/ngrok -config=ngrok/ngrok.cfg -subdomain shuzheng 7771 \ No newline at end of file diff --git a/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/controller/DemoController.java b/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/controller/DemoController.java index 1b380cd6..a828e773 100644 --- a/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/controller/DemoController.java +++ b/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/controller/DemoController.java @@ -1,12 +1,17 @@ package com.zheng.oss.web.controller; +import com.alibaba.fastjson.JSONObject; import com.aliyun.oss.OSSClient; import com.aliyun.oss.model.OSSObject; import com.aliyun.oss.model.PutObjectResult; +import com.zheng.common.base.BaseController; import com.zheng.oss.common.constant.OssConstant; +import com.zheng.oss.web.service.AliyunOssService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -17,12 +22,15 @@ import java.io.*; * oss测试 * Created by shuzheng on 2017/4/18. */ -@RestController +@Controller @RequestMapping("/demo") -public class DemoController { +public class DemoController extends BaseController { private static Logger _log = LoggerFactory.getLogger(DemoController.class); + @Autowired + private AliyunOssService aliyunOssService; + @Autowired private OSSClient aliyunOssClient; @@ -61,4 +69,13 @@ public class DemoController { return "http://" + OssConstant.ALIYUN_OSS_BUCKET_NAME + "." + OssConstant.ALIYUN_OSS_ENDPOINT + "/file.png"; } + @GetMapping("/aliyun/upload") + public String upload(Model model) { + JSONObject policy = aliyunOssService.policy(); + _log.info("policy={}", policy); + model.addAttribute("policy", policy); + model.addAttribute("policy", policy); + return thymeleaf("/aliyun/upload"); + } + } diff --git a/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/service/AliyunOssService.java b/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/service/AliyunOssService.java index aa342f59..843f7609 100644 --- a/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/service/AliyunOssService.java +++ b/zheng-oss/zheng-oss-web/src/main/java/com/zheng/oss/web/service/AliyunOssService.java @@ -5,6 +5,7 @@ import com.aliyun.oss.OSSClient; import com.aliyun.oss.common.utils.BinaryUtil; import com.aliyun.oss.model.MatchMode; import com.aliyun.oss.model.PolicyConditions; +import com.zheng.common.util.PropertiesFileUtil; import com.zheng.oss.common.constant.OssConstant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +42,7 @@ public class AliyunOssService { long maxSize = OssConstant.ALIYUN_OSS_MAX_SIZE * 1024 * 1024; // 回调 JSONObject callback = new JSONObject(); - callback.put("callbackUrl", "http://shuzheng.tunnel.qydev.com/aliyun/oss/callback"); + callback.put("callbackUrl", PropertiesFileUtil.getInstance("config").get("aliyun.oss.callback")); callback.put("callbackBody", "filename=${object}&size=${size}&mimeType=${mimeType}&height=${imageInfo.height}&width=${imageInfo.width}"); callback.put("callbackBodyType", "application/x-www-form-urlencoded"); try { diff --git a/zheng-oss/zheng-oss-web/src/main/resources/config.properties b/zheng-oss/zheng-oss-web/src/main/resources/config.properties index 82e53bfb..07158dc9 100644 --- a/zheng-oss/zheng-oss-web/src/main/resources/config.properties +++ b/zheng-oss/zheng-oss-web/src/main/resources/config.properties @@ -1,4 +1,6 @@ env=${profile.env} +app.name=${app.name} +zheng-ui.path=${zheng-ui.path} ### aliyun oss ### aliyun.oss.endpoint=${aliyun.oss.endpoint} @@ -7,4 +9,5 @@ aliyun.oss.accessKeyId=${aliyun.oss.accessKeyId} aliyun.oss.accessKeySecret=${aliyun.oss.accessKeySecret} aliyun.oss.bucketName=${aliyun.oss.bucketName} aliyun.oss.policy.expire=${aliyun.oss.policy.expire} -aliyun.oss.maxSize=${aliyun.oss.maxSize} \ No newline at end of file +aliyun.oss.maxSize=${aliyun.oss.maxSize} +aliyun.oss.callback=${aliyun.oss.callback} \ No newline at end of file diff --git a/zheng-oss/zheng-oss-web/src/main/resources/profiles/dev.properties b/zheng-oss/zheng-oss-web/src/main/resources/profiles/dev.properties index 1f1a8299..23172db7 100644 --- a/zheng-oss/zheng-oss-web/src/main/resources/profiles/dev.properties +++ b/zheng-oss/zheng-oss-web/src/main/resources/profiles/dev.properties @@ -1,4 +1,6 @@ profile.env=dev +app.name=zheng-oss-web +zheng-ui.path=http://ui.zhangshuzheng.cn:1000/ ### aliyun oss ### aliyun.oss.endpoint=oss-cn-shanghai.aliyuncs.com @@ -7,4 +9,5 @@ aliyun.oss.accessKeyId= aliyun.oss.accessKeySecret= aliyun.oss.bucketName=shuzheng aliyun.oss.policy.expire=30 -aliyun.oss.maxSize=10 \ No newline at end of file +aliyun.oss.maxSize=10 +aliyun.oss.callback=http://shuzheng.tunnel.qydev.com/aliyun/oss/callback \ No newline at end of file diff --git a/zheng-oss/zheng-oss-web/src/main/resources/profiles/prod.properties b/zheng-oss/zheng-oss-web/src/main/resources/profiles/prod.properties index 27e0a785..338f818c 100644 --- a/zheng-oss/zheng-oss-web/src/main/resources/profiles/prod.properties +++ b/zheng-oss/zheng-oss-web/src/main/resources/profiles/prod.properties @@ -1,4 +1,6 @@ profile.env=prod +app.name=zheng-oss-web +zheng-ui.path=http://ui.zhangshuzheng.cn:1000/ ### aliyun oss ### aliyun.oss.endpoint=oss-cn-shanghai.aliyuncs.com @@ -7,4 +9,5 @@ aliyun.oss.accessKeyId= aliyun.oss.accessKeySecret= aliyun.oss.bucketName=shuzheng_prod aliyun.oss.policy.expire=30 -aliyun.oss.maxSize=10 \ No newline at end of file +aliyun.oss.maxSize=10 +aliyun.oss.callback=http://shuzheng.tunnel.qydev.com/aliyun/oss/callback \ No newline at end of file diff --git a/zheng-oss/zheng-oss-web/src/main/resources/profiles/test.properties b/zheng-oss/zheng-oss-web/src/main/resources/profiles/test.properties index ff4f6ca1..7f960055 100644 --- a/zheng-oss/zheng-oss-web/src/main/resources/profiles/test.properties +++ b/zheng-oss/zheng-oss-web/src/main/resources/profiles/test.properties @@ -1,4 +1,6 @@ profile.env=test +app.name=zheng-oss-web +zheng-ui.path=http://ui.zhangshuzheng.cn:1000/ ### aliyun oss ### aliyun.oss.endpoint=oss-cn-shanghai.aliyuncs.com @@ -7,4 +9,5 @@ aliyun.oss.accessKeyId= aliyun.oss.accessKeySecret= aliyun.oss.bucketName=shuzheng_test aliyun.oss.policy.expire=30 -aliyun.oss.maxSize=10 \ No newline at end of file +aliyun.oss.maxSize=10 +aliyun.oss.callback=http://shuzheng.tunnel.qydev.com/aliyun/oss/callback \ No newline at end of file diff --git a/zheng-oss/zheng-oss-web/src/main/resources/springMVC-servlet.xml b/zheng-oss/zheng-oss-web/src/main/resources/springMVC-servlet.xml index 1aaa7fc3..945d61ce 100644 --- a/zheng-oss/zheng-oss-web/src/main/resources/springMVC-servlet.xml +++ b/zheng-oss/zheng-oss-web/src/main/resources/springMVC-servlet.xml @@ -1,14 +1,36 @@ + http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/zheng-oss/zheng-oss-web/src/main/resources/zheng-oss-client.properties b/zheng-oss/zheng-oss-web/src/main/resources/zheng-oss-client.properties new file mode 100644 index 00000000..572713f1 --- /dev/null +++ b/zheng-oss/zheng-oss-web/src/main/resources/zheng-oss-client.properties @@ -0,0 +1,2 @@ +### aliyun ### +aliyun.oss.policy=http://oss.zhangshuzheng.cn:7771/aliyun/oss/policy \ No newline at end of file