feat: extend asynclistObject support delimiter|marker|maxkeys to list object in Android

This commit is contained in:
luozhang002
2018-10-09 11:53:49 +08:00
committed by 罗章
parent c4af9ec8e2
commit 5585ea7ad4
5 changed files with 89 additions and 48 deletions

View File

@@ -16,51 +16,51 @@ import { styles } from '../CSS/global.js'
export class ObjectManager extends Component {
render() {
return(
<View style={styles.item}>
<Text style={styles.description}>管理文件</Text>
<View style={styles.detailitem}>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncHeadObject")}
title="asyncHeadObject"
color="#841584"
/>
</View>
<View style={styles.item}>
<Text style={styles.description}>管理文件</Text>
<View style={styles.detailitem}>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncHeadObject")}
title="asyncHeadObject"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncListObjects")}
title="asyncListObjects"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncListObjects")}
title="asyncListObjects"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncCopyObject")}
title="asyncCopyObject"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncCopyObject")}
title="asyncCopyObject"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"doesObjectExist")}
title="doesObjectExist"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"doesObjectExist")}
title="doesObjectExist"
color="#841584"
/>
</View>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncDeleteObject")}
title="asyncDeleteObject"
color="#841584"
/>
<View style={styles.button}>
<Button style={styles.button}
onPress={this.clickHandle.bind(this,"asyncDeleteObject")}
title="asyncDeleteObject"
color="#841584"
/>
</View>
</View>
</View>
</View>
)
)
}
clickHandle(e) {
switch(e) {
@@ -74,7 +74,9 @@ export class ObjectManager extends Component {
case "asyncListObjects" : {
console.log("asyncListObjects")
AliyunOSS.asyncListObjects('luozhang002').then((e) => {
AliyunOSS.asyncListObjects('luozhang002',{
prefix:'xxxx'
}).then((e) => {
console.log(e)
}).catch((e)=>{
console.log(e)
@@ -108,5 +110,4 @@ export class ObjectManager extends Component {
default :break;
}
}
}

View File

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

View File

@@ -344,8 +344,20 @@ AliyunOSS.asyncListBuckets().then((e) => {
```
### asyncListObjects
list objects in some conditions
parameters:
- name {String} bucket name
- options {Object}
- [delimiter] {String}
- [prefix] {String} search buckets using `prefix` key
- [marker] {String} search start from `marker`, including `marker` key
- [max-keys] {String|Number} max buckets, default is `100`, limit to `1000`
```
AliyunOSS.asyncListObjects('luozhang002').then((e)=>{
AliyunOSS.asyncListObjects('luozhang002', {
prefix:'xxxx'
}).then((e)=>{
console.log(e)
}).catch((e)=>{
console.log(e)

View File

@@ -92,12 +92,27 @@ public class AliyunObjectManager {
/**
* asyncListObjects
* @param bucketName
* @param prefix
* @param opitons {delimiter|prefix|marker|maxkeys}
* @param promise
*/
public void asyncListObjects(String bucketName,String prefix,final Promise promise) {
public void asyncListObjects(String bucketName, ReadableMap options, final Promise promise) {
ListObjectsRequest listObjects = new ListObjectsRequest(bucketName);
listObjects.setPrefix(prefix);
if(options.hasKey("prefix")) {
listObjects.setPrefix(options.getString("prefix"));
}
if(options.hasKey("delimiter")) {
listObjects.setDelimiter(options.getString("delimiter"));
}
if(options.hasKey("marker")) {
listObjects.setMarker(options.getString("delimiter"));
}
if(options.hasKey("maxkeys")) {
listObjects.setMaxKeys(options.getInt(String.valueOf(options.getInt("maxkeys"))));
}
// set success 、set fail 、set async request
OSSAsyncTask task = mOSS.asyncListObjects(listObjects, new OSSCompletedCallback<ListObjectsRequest, ListObjectsResult>() {

View File

@@ -332,8 +332,8 @@ public class RNAliyunOssModule extends ReactContextBaseJavaModule {
* @param promise
*/
@ReactMethod
public void asyncListObjects(String bucketName,String prefix,final Promise promise) {
mObjectManager.asyncListObjects(bucketName, prefix, promise);
public void asyncListObjects(String bucketName,ReadableMap options,final Promise promise) {
mObjectManager.asyncListObjects(bucketName, options, promise);
}
/**