Browse Source

Merge pull request #27 from aliyun/luozhang

asynclistobject 支持更多的参数
Albert Luo 6 years ago
parent
commit
8321c611d1
No account linked to committer's email address

+ 42
- 41
Example/Component/ObjectManager.js View File

16
 export class ObjectManager extends Component {  
16
 export class ObjectManager extends Component {  
17
   render() {  
17
   render() {  
18
      return(
18
      return(
19
-           <View style={styles.item}>
20
-      <Text style={styles.description}>管理文件</Text>
21
-      <View style={styles.detailitem}>
22
-        <View style={styles.button}>
23
-          <Button  style={styles.button}
24
-            onPress={this.clickHandle.bind(this,"asyncHeadObject")}
25
-            title="asyncHeadObject"
26
-            color="#841584"
27
-          />
28
-        </View>
19
+      <View style={styles.item}>
20
+        <Text style={styles.description}>管理文件</Text>
21
+        <View style={styles.detailitem}>
22
+          <View style={styles.button}>
23
+            <Button  style={styles.button}
24
+              onPress={this.clickHandle.bind(this,"asyncHeadObject")}
25
+              title="asyncHeadObject"
26
+              color="#841584"
27
+            />
28
+          </View>
29
 
29
 
30
-        <View style={styles.button}>
31
-          <Button  style={styles.button}
32
-            onPress={this.clickHandle.bind(this,"asyncListObjects")}
33
-            title="asyncListObjects"
34
-            color="#841584"
35
-          />
36
-        </View>
30
+          <View style={styles.button}>
31
+            <Button  style={styles.button}
32
+              onPress={this.clickHandle.bind(this,"asyncListObjects")}
33
+              title="asyncListObjects"
34
+              color="#841584"
35
+            />
36
+          </View>
37
 
37
 
38
-        <View style={styles.button}>
39
-          <Button  style={styles.button}
40
-            onPress={this.clickHandle.bind(this,"asyncCopyObject")}
41
-            title="asyncCopyObject"
42
-            color="#841584"
43
-          />
44
-        </View>
38
+          <View style={styles.button}>
39
+            <Button  style={styles.button}
40
+              onPress={this.clickHandle.bind(this,"asyncCopyObject")}
41
+              title="asyncCopyObject"
42
+              color="#841584"
43
+            />
44
+          </View>
45
 
45
 
46
-        <View style={styles.button}>
47
-          <Button  style={styles.button}
48
-            onPress={this.clickHandle.bind(this,"doesObjectExist")}
49
-            title="doesObjectExist"
50
-            color="#841584"
51
-          />
52
-        </View>
46
+          <View style={styles.button}>
47
+            <Button  style={styles.button}
48
+              onPress={this.clickHandle.bind(this,"doesObjectExist")}
49
+              title="doesObjectExist"
50
+              color="#841584"
51
+            />
52
+          </View>
53
 
53
 
54
-        <View style={styles.button}>
55
-          <Button  style={styles.button}
56
-            onPress={this.clickHandle.bind(this,"asyncDeleteObject")}
57
-            title="asyncDeleteObject"
58
-            color="#841584"
59
-          />
54
+          <View style={styles.button}>
55
+            <Button  style={styles.button}
56
+              onPress={this.clickHandle.bind(this,"asyncDeleteObject")}
57
+              title="asyncDeleteObject"
58
+              color="#841584"
59
+            />
60
+          </View>
60
         </View>
61
         </View>
61
       </View>
62
       </View>
62
-    </View>
63
-     )  
63
+    )  
64
   } 
64
   } 
65
   clickHandle(e) {
65
   clickHandle(e) {
66
     switch(e) {
66
     switch(e) {
74
 
74
 
75
       case "asyncListObjects" : {
75
       case "asyncListObjects" : {
76
         console.log("asyncListObjects")
76
         console.log("asyncListObjects")
77
-        AliyunOSS.asyncListObjects('luozhang002').then((e) => {
77
+        AliyunOSS.asyncListObjects('luozhang002',{
78
+          prefix:'xxxx'
79
+        }).then((e) => {
78
           console.log(e)
80
           console.log(e)
79
         }).catch((e)=>{
81
         }).catch((e)=>{
80
           console.log(e)
82
           console.log(e)
108
       default :break;
110
       default :break;
109
     }
111
     }
110
   }
112
   }
111
-
112
  }
113
  }

+ 14
- 1
README-CN.md View File

334
 ```
334
 ```
335
 ### asyncListObjects
335
 ### asyncListObjects
336
 
336
 
337
+列举指定bucket下的objects
338
+
339
+parameters:
340
+
341
+- name {String} bucket name
342
+- options {Object}
343
+  - [delimiter] {String} 用于对Object名字进行分组的字符。所有名字包含指定的前缀且第一次出现delimiter字符之间的object作为一组元素: CommonPrefixes。
344
+  - [marker] {String} 设定结果从marker之后按字母排序的第一个开始返回。
345
+  - [maxkeys] {Number} 限定此次返回object的最大数,如果不设定,默认为100,maxkeys取值不能大于1000。
346
+  - [prefix]  {String} 限定返回的object key必须以prefix作为前缀。注意使用prefix查询时,返回的key中仍会包含prefix。
347
+
337
 ```
348
 ```
338
- AliyunOSS.asyncListObjects('luozhang002').then((e)=>{
349
+ AliyunOSS.asyncListObjects('luozhang002',{
350
+    prefix:'xxxx'
351
+  }).then((e)=>{
339
     console.log(e)
352
     console.log(e)
340
   }).catch((e)=>{
353
   }).catch((e)=>{
341
      console.log(e)
354
      console.log(e)

+ 13
- 1
README.md View File

344
 ```
344
 ```
345
 ### asyncListObjects
345
 ### asyncListObjects
346
 
346
 
347
+list objects in some conditions
348
+
349
+parameters:
350
+
351
+- name {String} bucket name
352
+- options {Object}
353
+  - [delimiter] {String} 
354
+  - [prefix] {String} search buckets using `prefix` key
355
+  - [marker] {String} search start from `marker`, including `marker` key
356
+  - [max-keys] {String|Number} max buckets, default is `100`, limit to `1000` 
347
 ```
357
 ```
348
- AliyunOSS.asyncListObjects('luozhang002').then((e)=>{
358
+ AliyunOSS.asyncListObjects('luozhang002', {
359
+    prefix:'xxxx'
360
+}).then((e)=>{
349
     console.log(e)
361
     console.log(e)
350
   }).catch((e)=>{
362
   }).catch((e)=>{
351
      console.log(e)
363
      console.log(e)

+ 18
- 3
android/src/main/java/com/reactlibrary/AliyunObjectManager.java View File

92
     /**
92
     /**
93
      * asyncListObjects
93
      * asyncListObjects
94
      * @param bucketName
94
      * @param bucketName
95
-     * @param prefix
95
+     * @param opitons {delimiter|prefix|marker|maxkeys}
96
      * @param promise
96
      * @param promise
97
      */
97
      */
98
-    public void asyncListObjects(String bucketName,String prefix,final Promise promise) {
98
+    public void asyncListObjects(String bucketName, ReadableMap options, final Promise promise) {
99
         ListObjectsRequest listObjects = new ListObjectsRequest(bucketName);
99
         ListObjectsRequest listObjects = new ListObjectsRequest(bucketName);
100
-        listObjects.setPrefix(prefix);
100
+
101
+        if(options.hasKey("prefix")) {
102
+            listObjects.setPrefix(options.getString("prefix"));
103
+        }
104
+
105
+        if(options.hasKey("delimiter")) {
106
+            listObjects.setDelimiter(options.getString("delimiter"));
107
+        }
108
+
109
+        if(options.hasKey("marker")) {
110
+            listObjects.setMarker(options.getString("delimiter"));
111
+        }
112
+
113
+        if(options.hasKey("maxkeys")) {
114
+            listObjects.setMaxKeys(options.getInt(String.valueOf(options.getInt("maxkeys"))));
115
+        }
101
 
116
 
102
         // set success 、set fail 、set async request
117
         // set success 、set fail 、set async request
103
         OSSAsyncTask task = mOSS.asyncListObjects(listObjects, new OSSCompletedCallback<ListObjectsRequest, ListObjectsResult>() {
118
         OSSAsyncTask task = mOSS.asyncListObjects(listObjects, new OSSCompletedCallback<ListObjectsRequest, ListObjectsResult>() {

+ 2
- 2
android/src/main/java/com/reactlibrary/RNAliyunOssModule.java View File

332
      * @param promise
332
      * @param promise
333
      */
333
      */
334
     @ReactMethod
334
     @ReactMethod
335
-    public void asyncListObjects(String bucketName,String prefix,final Promise promise) {
336
-        mObjectManager.asyncListObjects(bucketName, prefix, promise);
335
+    public void asyncListObjects(String bucketName,ReadableMap options,final Promise promise) {
336
+        mObjectManager.asyncListObjects(bucketName, options, promise);
337
     }
337
     }
338
 
338
 
339
     /**
339
     /**

+ 2
- 2
index.js View File

143
      * Asynchronously getAsyncObjects
143
      * Asynchronously getAsyncObjects
144
      */
144
      */
145
 
145
 
146
-    asyncListObjects (bucketName,prefix='') {
147
-        return RNAliyunOSS.asyncListObjects(bucketName,prefix,)
146
+    asyncListObjects (bucketName,options) {
147
+        return RNAliyunOSS.asyncListObjects(bucketName,options)
148
     },
148
     },
149
 
149
 
150
 
150
 

+ 18
- 6
ios/RNAliyunOSS+OBJECT.m View File

13
  asyncListObjects
13
  asyncListObjects
14
  */
14
  */
15
 
15
 
16
-RCT_REMAP_METHOD(asyncListObjects, bucketName:(NSString*)bucketName prefix:(NSString*)prefix resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
16
+RCT_REMAP_METHOD(asyncListObjects, bucketName:(NSString*)bucketName options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
17
     OSSGetBucketRequest * getBucket = [OSSGetBucketRequest new];
17
     OSSGetBucketRequest * getBucket = [OSSGetBucketRequest new];
18
     getBucket.bucketName = bucketName;
18
     getBucket.bucketName = bucketName;
19
     // 可选参数,具体含义参考:https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket
19
     // 可选参数,具体含义参考:https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket
20
     // getBucket.marker = @"";
20
     // getBucket.marker = @"";
21
-    getBucket.prefix = prefix;
22
     // getBucket.delimiter = @"";
21
     // getBucket.delimiter = @"";
22
+    
23
+    if([options objectForKey:@"delimiter"]) {
24
+        getBucket.delimiter = [options objectForKey:@"delimiter"];
25
+    }
26
+    
27
+    if([options objectForKey:@"marker"]) {
28
+        getBucket.delimiter = [options objectForKey:@"marker"];
29
+    }
30
+    
31
+    if([options objectForKey:@"prefix"]) {
32
+        getBucket.delimiter = [options objectForKey:@"prefix"];
33
+    }
34
+    
35
+    if([options objectForKey:@"maxkeys"]) {
36
+        getBucket.delimiter = [options objectForKey:@"maxkeys"];
37
+    }
38
+    
23
     OSSTask * getBucketTask = [self.client getBucket:getBucket];
39
     OSSTask * getBucketTask = [self.client getBucket:getBucket];
24
     [getBucketTask continueWithBlock:^id(OSSTask *task) {
40
     [getBucketTask continueWithBlock:^id(OSSTask *task) {
25
         if (!task.error) {
41
         if (!task.error) {
26
             OSSGetBucketResult * result = task.result;
42
             OSSGetBucketResult * result = task.result;
27
-            //            NSLog(@"get bucket success!");
28
-            //            for (NSDictionary * objectInfo in result.contents) {
29
-            //                NSLog(@"list object: %@", objectInfo);
30
-            //            }
31
             resolve(result.contents);
43
             resolve(result.contents);
32
         } else {
44
         } else {
33
             NSLog(@"get bucket failed, error: %@", task.error);
45
             NSLog(@"get bucket failed, error: %@", task.error);