Skip to content

Commit

Permalink
Merge branch 'master' into dev_request_getobjectacl
Browse files Browse the repository at this point in the history
Conflicts:
	oss-android-sdk/src/main/java/com/alibaba/sdk/android/oss/OSS.java
	oss-android-sdk/src/main/java/com/alibaba/sdk/android/oss/OSSClient.java
	oss-android-sdk/src/main/java/com/alibaba/sdk/android/oss/OSSImpl.java
	oss-android-sdk/src/main/java/com/alibaba/sdk/android/oss/common/utils/OSSUtils.java
	oss-android-sdk/src/main/java/com/alibaba/sdk/android/oss/internal/InternalRequestOperation.java
	oss-android-sdk/src/main/java/com/alibaba/sdk/android/oss/internal/ResponseParsers.java
  • Loading branch information
1019272778 committed Mar 15, 2018
2 parents 196e59d + 3c07a15 commit c253536
Show file tree
Hide file tree
Showing 36 changed files with 1,415 additions and 761 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public OssService initOSS(String endpoint, String bucket, UIDisplayer displayer)
// String SK = "******";
// credentialProvider = new PlainTextAKSKCredentialProvider(AK,SK)
// 以下是使用STS Sever方式。
// 如果用STS鉴权模式,推荐使用OSSAuthCredentialProvider方式直接访问鉴权应用服务器,token过期后可以自动更新。
// 详见:https://help.aliyun.com/document_detail/31920.html
// OSSClient的生命周期和应用程序的生命周期保持一致即可。在应用程序启动时创建一个ossClient,在应用程序结束时销毁即可。


OSSCredentialProvider credentialProvider;
//使用自己的获取STSToken的类
Expand Down
12 changes: 9 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
阿里云计算开放服务软件开发工具包Android版
阿里云计算开放服务软件开发工具包Android版
Aliyun Open Services SDK for Android

版权所有 (C)阿里云计算有限公司
Expand All @@ -14,13 +14,19 @@ http://www.aliyun.com


更新日志:
2017/2/1

2018/02/12
- release 2.7.3

1.fix bug about the value of clientException’s isCanceledException doesnot match cancel operation
.
2.fix bug about multipartUploadTask doesnot work.

2018/2/1
- relese 2.7.0
1. add callback trigger function.
2. fix resumeupload freeze bug.


2017/1/22
2018/1/22
- relese 2.6.0
1. SHA1 check when putObject and seqenceupload.
2. fix bug when resumeupload object what is smaller than 256k.
Expand Down
4 changes: 2 additions & 2 deletions oss-android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 28
versionName "2.7.0"
versionCode 31
versionName "2.7.3"
}

buildTypes {
Expand Down
Binary file added oss-android-sdk/src/androidTest/assets/shilan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.alibaba.sdk.android;

import android.test.AndroidTestCase;

import com.alibaba.sdk.android.oss.ClientConfiguration;
import com.alibaba.sdk.android.oss.OSS;
import com.alibaba.sdk.android.oss.OSSClient;
import com.alibaba.sdk.android.oss.common.OSSLog;
import com.alibaba.sdk.android.oss.model.CreateBucketRequest;

import static com.alibaba.sdk.android.oss.model.CannedAccessControlList.PublicReadWrite;

/**
* Created by jingdan on 2018/3/1.
*/

public abstract class BaseTestCase extends AndroidTestCase {
protected String mBucketName;
protected String mPublicBucketName;
protected OSS oss;

abstract void initTestData() throws Exception;

protected void initOSSClient() {
ClientConfiguration conf = new ClientConfiguration();
conf.setConnectionTimeout(15 * 1000); // 连接超时,默认15秒
conf.setSocketTimeout(15 * 1000); // socket超时,默认15秒
conf.setMaxConcurrentRequest(5); // 最大并发请求书,默认5个
conf.setMaxErrorRetry(2); // 失败后最大重试次数,默认2次
oss = new OSSClient(getContext(), OSSTestConfig.ENDPOINT, OSSTestConfig.credentialProvider);
}

@Override
protected void setUp() throws Exception {
super.setUp();
mBucketName = OSSTestUtils.produceBucketName(getName());
mPublicBucketName = OSSTestUtils.produceBucketName("public" + getName());
OSSTestConfig.instance(getContext());
if (oss == null) {
OSSLog.enableLog();
initOSSClient();
try {
CreateBucketRequest request = new CreateBucketRequest(mBucketName);
oss.createBucket(request);
CreateBucketRequest request2 = new CreateBucketRequest(mPublicBucketName);
request2.setBucketACL(PublicReadWrite);
oss.createBucket(request2);
initTestData();
} catch (Exception e) {
}

}
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
try {
OSSTestUtils.cleanBucket(oss, mBucketName);
OSSTestUtils.cleanBucket(oss, mPublicBucketName);
} catch (Exception e) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.alibaba.sdk.android.oss.model.AppendObjectRequest;
import com.alibaba.sdk.android.oss.model.CompleteMultipartUploadRequest;
import com.alibaba.sdk.android.oss.model.CompleteMultipartUploadResult;
import com.alibaba.sdk.android.oss.model.CreateBucketRequest;
import com.alibaba.sdk.android.oss.model.DeleteObjectRequest;
import com.alibaba.sdk.android.oss.model.GetObjectRequest;
import com.alibaba.sdk.android.oss.model.GetObjectResult;
Expand All @@ -35,26 +36,23 @@
* Created by jingdan on 2017/11/29.
*/

public class CRC64Test extends AndroidTestCase {
public class CRC64Test extends BaseTestCase {

private String testFile = "guihua.zip";

private OSS oss;

@Override
protected void setUp() throws Exception {
OSSTestConfig.instance(getContext());
if (oss == null) {
OSSLog.enableLog();
oss = new OSSClient(getContext(), OSSTestConfig.ENDPOINT, OSSTestConfig.authCredentialProvider);
}
void initTestData() {
OSSTestConfig.initLocalFile();
OSSTestConfig.initDemoFile("guihua.zip");
OSSTestConfig.initDemoFile("demo.pdf");
}

public void testCRC64GetObject() throws Exception {
GetObjectRequest request = new GetObjectRequest(OSSTestConfig.ANDROID_TEST_BUCKET, testFile);
PutObjectRequest put = new PutObjectRequest(mBucketName, testFile,
OSSTestConfig.FILE_DIR + "guihua.zip");
oss.putObject(put);

GetObjectRequest request = new GetObjectRequest(mBucketName, testFile);
request.setCRC64(OSSRequest.CRC64Config.YES);
request.setProgressListener(new OSSProgressCallback<GetObjectRequest>() {
@Override
Expand All @@ -75,7 +73,7 @@ public void onProgress(GetObjectRequest request, long currentSize, long totalSiz
}

public void testCRC64PutObject() throws Exception {
PutObjectRequest put = new PutObjectRequest(OSSTestConfig.ANDROID_TEST_BUCKET, testFile,
PutObjectRequest put = new PutObjectRequest(mBucketName, testFile,
OSSTestConfig.FILE_DIR + testFile);
OSSTestConfig.TestPutCallback putCallback = new OSSTestConfig.TestPutCallback();
put.setCRC64(OSSRequest.CRC64Config.YES);
Expand All @@ -93,10 +91,10 @@ public void onProgress(PutObjectRequest request, long currentSize, long totalSiz
}

public void testCRC64AppendObject() throws Exception {
DeleteObjectRequest delete = new DeleteObjectRequest(OSSTestConfig.ANDROID_TEST_BUCKET, "append_file1m");
DeleteObjectRequest delete = new DeleteObjectRequest(mBucketName, "append_file1m");
oss.deleteObject(delete);

AppendObjectRequest append = new AppendObjectRequest(OSSTestConfig.ANDROID_TEST_BUCKET, "append_file1m",
AppendObjectRequest append = new AppendObjectRequest(mBucketName, "append_file1m",
OSSTestConfig.FILE_DIR + "file1m");
append.setInitCRC64(0L);
append.setCRC64(OSSRequest.CRC64Config.YES);
Expand Down Expand Up @@ -131,14 +129,14 @@ public void onProgress(AppendObjectRequest request, long currentSize, long total
public void testUploadPartAndCompleteCRC64() throws Exception {
String objectKey = "multipart";
List<PartETag> partETagList = new ArrayList<PartETag>();
InitiateMultipartUploadRequest init = new InitiateMultipartUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey);
InitiateMultipartUploadRequest init = new InitiateMultipartUploadRequest(mBucketName, objectKey);
InitiateMultipartUploadResult initResult = oss.initMultipartUpload(init);

assertNotNull(initResult.getUploadId());
String uploadId = initResult.getUploadId();

byte[] data = new byte[100 * 1024];
UploadPartRequest uploadPart1 = new UploadPartRequest(OSSTestConfig.ANDROID_TEST_BUCKET,
UploadPartRequest uploadPart1 = new UploadPartRequest(mBucketName,
objectKey, uploadId, 1);
uploadPart1.setPartContent(data);
uploadPart1.setCRC64(OSSRequest.CRC64Config.YES);
Expand All @@ -149,7 +147,7 @@ public void testUploadPartAndCompleteCRC64() throws Exception {
eTag1.setCRC64(uploadPartResult1.getClientCRC());
partETagList.add(eTag1);

UploadPartRequest uploadPart2 = new UploadPartRequest(OSSTestConfig.ANDROID_TEST_BUCKET,
UploadPartRequest uploadPart2 = new UploadPartRequest(mBucketName,
objectKey, uploadId, 2);
uploadPart2.setPartContent(data);
uploadPart2.setCRC64(OSSRequest.CRC64Config.YES);
Expand All @@ -162,7 +160,7 @@ public void testUploadPartAndCompleteCRC64() throws Exception {


CompleteMultipartUploadRequest complete
= new CompleteMultipartUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey, uploadId, partETagList);
= new CompleteMultipartUploadRequest(mBucketName, objectKey, uploadId, partETagList);
complete.setCRC64(OSSRequest.CRC64Config.YES);
oss.completeMultipartUpload(complete);

Expand All @@ -171,14 +169,14 @@ public void testUploadPartAndCompleteCRC64() throws Exception {
public void testCRC64Error() throws Exception {
String objectKey = "multipart";
List<PartETag> partETagList = new ArrayList<PartETag>();
InitiateMultipartUploadRequest init = new InitiateMultipartUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey);
InitiateMultipartUploadRequest init = new InitiateMultipartUploadRequest(mBucketName, objectKey);
InitiateMultipartUploadResult initResult = oss.initMultipartUpload(init);

assertNotNull(initResult.getUploadId());
String uploadId = initResult.getUploadId();

byte[] data = new byte[100 * 1024];
UploadPartRequest uploadPart1 = new UploadPartRequest(OSSTestConfig.ANDROID_TEST_BUCKET,
UploadPartRequest uploadPart1 = new UploadPartRequest(mBucketName,
objectKey, uploadId, 1);
uploadPart1.setPartContent(data);
uploadPart1.setCRC64(OSSRequest.CRC64Config.YES);
Expand All @@ -189,7 +187,7 @@ public void testCRC64Error() throws Exception {
eTag1.setCRC64(uploadPartResult1.getClientCRC());
partETagList.add(eTag1);

UploadPartRequest uploadPart2 = new UploadPartRequest(OSSTestConfig.ANDROID_TEST_BUCKET,
UploadPartRequest uploadPart2 = new UploadPartRequest(mBucketName,
objectKey, uploadId, 2);
uploadPart2.setPartContent(data);
uploadPart2.setCRC64(OSSRequest.CRC64Config.YES);
Expand All @@ -202,7 +200,7 @@ public void testCRC64Error() throws Exception {
partETagList.add(eTag2);

CompleteMultipartUploadRequest complete
= new CompleteMultipartUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey, uploadId, partETagList);
= new CompleteMultipartUploadRequest(mBucketName, objectKey, uploadId, partETagList);
complete.setCRC64(OSSRequest.CRC64Config.YES);
try {
oss.completeMultipartUpload(complete);
Expand All @@ -215,7 +213,7 @@ public void testCRC64Error() throws Exception {
public void testMultipartUploadWithCRC64() throws Exception {
String filePath = OSSTestConfig.FILE_DIR.concat(testFile);
String objectKey = "mul-" + testFile;
MultipartUploadRequest request = new MultipartUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey, filePath);
MultipartUploadRequest request = new MultipartUploadRequest(mBucketName, objectKey, filePath);
request.setCRC64(OSSRequest.CRC64Config.YES);
request.setProgressCallback(new OSSProgressCallback() {
@Override
Expand All @@ -233,7 +231,7 @@ public void onProgress(Object request, long currentSize, long totalSize) {
public void testResumableMultipartUploadWithCRC64() throws Exception {
String filePath = OSSTestConfig.FILE_DIR.concat(testFile);
String objectKey = "mul-" + testFile;
ResumableUploadRequest request = new ResumableUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey, filePath);
ResumableUploadRequest request = new ResumableUploadRequest(mBucketName, objectKey, filePath);
request.setCRC64(OSSRequest.CRC64Config.YES);
request.setDeleteUploadOnCancelling(false);
request.setProgressCallback(new OSSProgressCallback() {
Expand All @@ -251,7 +249,7 @@ public void onProgress(Object request, long currentSize, long totalSize) {

public void testResumableMultipartUploadCancelWithCRC64() throws Exception {
final String objectKey = "file10m";
ResumableUploadRequest request = new ResumableUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey,
ResumableUploadRequest request = new ResumableUploadRequest(mBucketName, objectKey,
OSSTestConfig.FILE_DIR + objectKey, OSSTestConfig.FILE_DIR);
request.setDeleteUploadOnCancelling(false);
request.setCRC64(OSSRequest.CRC64Config.YES);
Expand Down Expand Up @@ -284,7 +282,7 @@ public void onProgress(ResumableUploadRequest request, long currentSize, long to

Thread.sleep(1000l);

request = new ResumableUploadRequest(OSSTestConfig.ANDROID_TEST_BUCKET, objectKey,
request = new ResumableUploadRequest(mBucketName, objectKey,
OSSTestConfig.FILE_DIR + objectKey, OSSTestConfig.FILE_DIR);
request.setDeleteUploadOnCancelling(false);
request.setCRC64(OSSRequest.CRC64Config.YES);
Expand Down
Loading

0 comments on commit c253536

Please sign in to comment.