增加aliyun-oss演示
This commit is contained in:
parent
8be762c083
commit
825771c3ae
|
@ -1 +1 @@
|
|||
start ngrok/ngrok -config=ngrok/ngrok.cfg -subdomain shuzheng 80
|
||||
start ngrok/ngrok -config=ngrok/ngrok.cfg -subdomain shuzheng 7771
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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}
|
||||
aliyun.oss.maxSize=${aliyun.oss.maxSize}
|
||||
aliyun.oss.callback=${aliyun.oss.callback}
|
|
@ -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
|
||||
aliyun.oss.maxSize=10
|
||||
aliyun.oss.callback=http://shuzheng.tunnel.qydev.com/aliyun/oss/callback
|
|
@ -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
|
||||
aliyun.oss.maxSize=10
|
||||
aliyun.oss.callback=http://shuzheng.tunnel.qydev.com/aliyun/oss/callback
|
|
@ -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
|
||||
aliyun.oss.maxSize=10
|
||||
aliyun.oss.callback=http://shuzheng.tunnel.qydev.com/aliyun/oss/callback
|
|
@ -1,14 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/mvc
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
|
||||
http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<!-- 根目录'/'对应页面 -->
|
||||
<mvc:view-controller path="/" view-name="/index"/>
|
||||
|
||||
<context:property-placeholder location="classpath:config.properties"/>
|
||||
|
||||
<!-- thymeleaf视图 -->
|
||||
<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
|
||||
<property name="order" value="0"/>
|
||||
<property name="prefix" value="${zheng-ui.path}"/>
|
||||
<property name="suffix" value=""/>
|
||||
<property name="templateMode" value="HTML"/>
|
||||
<property name="cacheable" value="false"/>
|
||||
<!--<property name="cacheable" value="true"/>-->
|
||||
<!--<property name="cacheTTLMs" value="10000"/>-->
|
||||
</bean>
|
||||
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
|
||||
<property name="templateResolver" ref="templateResolver"/>
|
||||
<property name="enableSpringELCompiler" value="true"/>
|
||||
</bean>
|
||||
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
|
||||
<property name="templateEngine" ref="templateEngine"/>
|
||||
<property name="characterEncoding" value="UTF-8"/>
|
||||
<property name="viewNames" value="*.html"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,2 @@
|
|||
### aliyun ###
|
||||
aliyun.oss.policy=http://oss.zhangshuzheng.cn:7771/aliyun/oss/policy
|
Loading…
Reference in New Issue