Skip to content

Commit

Permalink
添加使用说明
Browse files Browse the repository at this point in the history
fix bug

Signed-off-by: Long Yuan <[email protected]>
  • Loading branch information
xiaolongyuan committed Jul 31, 2015
1 parent 7e92268 commit 0ec8fa0
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 33 deletions.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
#aliyun-oss-sign-url
阿里云Oss(针对私有bucket)的加签工具、外链工具 不依赖不依赖阿里云OSS sdk、第三方工具包 Java、Android平台都可以使用


/**
* STS 方式生成外链
* @throws URISyntaxException
*/
@Test
public void generatePresignedUrl() throws URISyntaxException {

String bucketName="test";
String keyId="STS.lNPyUWj3Cw4RljIWj915";
String keySecret="wbbeqWA72EdvpWsOXctBNRENbSwpB5NfyZq0Paz3";
String securityToken="CAES0AMIARKAAV0xbMc5QxHSaRCJquxvE8EiT+nKdG/ngHS98ywDkUmsTcLCyIyjFdYBLrShCWizY3" +
"/0iMO9yUFQDB4FteiXFR38HdKCFGe35xj6TmNFbPHclMcAIO9feKMcdIh9oHkiSv8OY98K9oe+vy" +
"+XYJetK6skjqmnJUBhawfOYEQayNrvGhhTVFMubE5QeVVXajNDdzRSbGpJV2o5MTUiEDEyMTc5Mzc1NTQwNjg3NjcqCGxvbmd5dWFuMIzT6pDuKToGUnNhTUQ1QoMCCgExGm8KBUFsbG93EikKDEFjdGlvbkVxdWFscxIGQWN0aW9uGhEKD29zczpMaXN0T2JqZWN0cxI7Cg5SZXNvdXJjZUVxdWFscxIIUmVzb3VyY2UaHwodYWNzOm9zczoqOio6cW0taW1nLWlmaXR0aW5nLyoajAEKBUFsbG93EicKDEFjdGlvbkVxdWFscxIGQWN0aW9uGg8KDW9zczpHZXRPYmplY3QSOwoOUmVzb3VyY2VFcXVhbHMSCFJlc291cmNlGh8KHWFjczpvc3M6KjoqOnFtLWltZy1pZml0dGluZy8qEh0KClN0cmluZ0xpa2USCm9zczpQcmVmaXgaAwoBKg==";
Date expiration= new Date(System.currentTimeMillis() + (60 * 60 * 1000));

URI endpoint = new URI("http://test.ifitting.com");

URL url = UrlSignUtils.generatePresignedUrl(keyId, keySecret, securityToken, expiration, bucketName, "1.jpg", endpoint);
System.out.println(url.toString());
}
/**
* 主A/K 方式生成外链
* @throws URISyntaxException
*/
@Test
public void generatePresignedUrl2() throws URISyntaxException {

String bucketName="test";
String keyId="lNPyUWj3Cw4RljIWj915";
String keySecret="wbbeqWA72EdvpWsOXctBNRENbSwpB5NfyZq0Paz3";
Date expiration= new Date(System.currentTimeMillis() + (60 * 60 * 1000));

URI endpoint = new URI("http://test.ifitting.com");

URL url = UrlSignUtils.generatePresignedUrl(keyId, keySecret, expiration, bucketName, "1.jpg", endpoint);
System.out.println(url.toString());
}








筱龙缘
2015-07-31
57 changes: 29 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<name>aliyun :: module :: aliyun-oss-sign-url</name>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-oss-sign-url</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
Expand Down Expand Up @@ -64,34 +65,34 @@
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>Public Repositories</name>
<url>http://192.168.199.78:9999/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>

<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.199.78:9999/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.199.78:9999/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<!--<pluginRepositories>-->
<!--<pluginRepository>-->
<!--<id>public</id>-->
<!--<name>Public Repositories</name>-->
<!--<url>http://192.168.199.78:9999/nexus/content/groups/public</url>-->
<!--<releases>-->
<!--<enabled>true</enabled>-->
<!--</releases>-->
<!--<snapshots>-->
<!--<enabled>true</enabled>-->
<!--<updatePolicy>always</updatePolicy>-->
<!--<checksumPolicy>warn</checksumPolicy>-->
<!--</snapshots>-->
<!--</pluginRepository>-->
<!--</pluginRepositories>-->

<!--<distributionManagement>-->
<!--<repository>-->
<!--<id>releases</id>-->
<!--<name>Nexus Release Repository</name>-->
<!--<url>http://192.168.199.78:9999/nexus/content/repositories/releases/</url>-->
<!--</repository>-->
<!--<snapshotRepository>-->
<!--<id>snapshots</id>-->
<!--<name>Nexus Snapshot Repository</name>-->
<!--<url>http://192.168.199.78:9999/nexus/content/repositories/snapshots/</url>-->
<!--</snapshotRepository>-->
<!--</distributionManagement>-->


<build>
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/com/aliyun/oss/urlsign/internal/UrlSignUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,32 @@ public static URL generatePresignedUrl(String accessId, String accessKey,
String key,
URI endpoint

)
throws MalformedURLException {
){
return generatePresignedUrl(accessId, accessKey, null, Boolean.FALSE, method, expiration,
bucketName, key, endpoint, null, null, new HashMap<String, String>(), new HashMap<String, String>(), null);

}

/**
* 主 A/K 方式获取
* @param accessId
* @param accessKey
* @param expiration
* @param bucketName
* @param key
* @param endpoint 阿里云三级域名、自定义的oss bucket域名 注意 目前采用sts方式暂不支持阿里云IMG服务(即cdn域名无法使用)
* @return
* @throws MalformedURLException
*/
public static URL generatePresignedUrl(String accessId, String accessKey,
Date expiration,
String bucketName,
String key,
URI endpoint

) {

HttpMethod method = HttpMethod.GET;
return generatePresignedUrl(accessId, accessKey, null, Boolean.FALSE, method, expiration,
bucketName, key, endpoint, null, null, new HashMap<String, String>(), new HashMap<String, String>(), null);

Expand Down
26 changes: 24 additions & 2 deletions src/test/java/com/aliyun/oss/urlsign/test/UrlSignTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,42 @@
*/
public class UrlSignTest {


/**
* STS 方式生成外链
* @throws URISyntaxException
*/
@Test
public void generatePresignedUrl() throws URISyntaxException {

String bucketName="qm-img-ifitting";
String bucketName="test";
String keyId="STS.lNPyUWj3Cw4RljIWj915";
String keySecret="wbbeqWA72EdvpWsOXctBNRENbSwpB5NfyZq0Paz3";
String securityToken="CAES0AMIARKAAV0xbMc5QxHSaRCJquxvE8EiT+nKdG/ngHS98ywDkUmsTcLCyIyjFdYBLrShCWizY3" +
"/0iMO9yUFQDB4FteiXFR38HdKCFGe35xj6TmNFbPHclMcAIO9feKMcdIh9oHkiSv8OY98K9oe+vy" +
"+XYJetK6skjqmnJUBhawfOYEQayNrvGhhTVFMubE5QeVVXajNDdzRSbGpJV2o5MTUiEDEyMTc5Mzc1NTQwNjg3NjcqCGxvbmd5dWFuMIzT6pDuKToGUnNhTUQ1QoMCCgExGm8KBUFsbG93EikKDEFjdGlvbkVxdWFscxIGQWN0aW9uGhEKD29zczpMaXN0T2JqZWN0cxI7Cg5SZXNvdXJjZUVxdWFscxIIUmVzb3VyY2UaHwodYWNzOm9zczoqOio6cW0taW1nLWlmaXR0aW5nLyoajAEKBUFsbG93EicKDEFjdGlvbkVxdWFscxIGQWN0aW9uGg8KDW9zczpHZXRPYmplY3QSOwoOUmVzb3VyY2VFcXVhbHMSCFJlc291cmNlGh8KHWFjczpvc3M6KjoqOnFtLWltZy1pZml0dGluZy8qEh0KClN0cmluZ0xpa2USCm9zczpQcmVmaXgaAwoBKg==";
Date expiration= new Date(System.currentTimeMillis() + (60 * 60 * 1000));

URI endpoint = new URI("http://ifitimg.ifitting.me");
URI endpoint = new URI("http://test.ifitting.com");

URL url = UrlSignUtils.generatePresignedUrl(keyId, keySecret, securityToken, expiration, bucketName, "1.jpg", endpoint);
System.out.println(url.toString());
}
/**
* 主A/K 方式生成外链
* @throws URISyntaxException
*/
@Test
public void generatePresignedUrl2() throws URISyntaxException {

String bucketName="test";
String keyId="lNPyUWj3Cw4RljIWj915";
String keySecret="wbbeqWA72EdvpWsOXctBNRENbSwpB5NfyZq0Paz3";
Date expiration= new Date(System.currentTimeMillis() + (60 * 60 * 1000));

URI endpoint = new URI("http://test.ifitting.com");

URL url = UrlSignUtils.generatePresignedUrl(keyId, keySecret, expiration, bucketName, "1.jpg", endpoint);
System.out.println(url.toString());
}
}

0 comments on commit 0ec8fa0

Please sign in to comment.