Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/BatchDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.storage.model.FileListing;
import com.qiniu.util.Auth;


public class BatchDemo {
public static void main(String args[]){
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "Access_Key";
String SECRET_KEY = "Secret_Key";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth);

//创建Batch类型的operations对象
BucketManager.Batch operations = new BucketManager.Batch();

//第一组源空间名、原文件名,目的空间名、目的文件名
String bucketFrom1 = "yourbucket";
String keyFrom1 = "srckey1";
String bucketTo1 = "yourbucket";
String keyTo1 = "destkey1";

//第二组源空间名、原文件名,目的空间名、目的文件名
String bucketFrom2 = "yourbucket";
String keyFrom2 = "srckey2";
String bucketTo2 = "yourbucket";
String keyTo2 = "destkey2";


try {
//调用批量操作的batch方法
Response res = bucketManager.batch(operations.move(bucketFrom1, keyFrom1, bucketTo1, keyTo1)
.move(bucketFrom2, keyFrom2, bucketTo2, keyTo2));

System.out.println(res.toString());

} catch (QiniuException e) {
//捕获异常信息
Response r = e.response;
System.out.println(r.toString());
}
}
}
33 changes: 33 additions & 0 deletions examples/FetchDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.util.Auth;


public class FetchDemo {
public static void main(String args[]){
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "Access_Key";
String SECRET_KEY = "Secret_Key";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth);

//文件保存的空间名和文件名
String bucket = "yourbucket";
String key = "yourkey";

//要fetch的url
String url = "url";

try {
//调用fetch方法抓取文件
bucketManager.fetch(url, bucket,key);
} catch (QiniuException e) {
//捕获异常信息
Response r = e.response;
System.out.println(r.toString());
}
}
}
40 changes: 40 additions & 0 deletions examples/ListDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.storage.model.FileListing;
import com.qiniu.util.Auth;


public class ListDemo {
public static void main(String args[]){
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "Access_Key";
String SECRET_KEY = "Secret_Key";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth);

//要列举文件的空间名
String bucket = "yourbucket";

try {
//调用listFiles方法列举指定空间的指定文件
//参数一:bucket 空间名
//参数二:prefix 文件名前缀
//参数三:marker 上一次获取文件列表时返回的 marker
//参数四:limit 每次迭代的长度限制,最大1000,推荐值 100
//参数五:delimiter 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
FileListing fileListing = bucketManager.listFiles(bucket,null,null,10,null);
FileInfo[] items = fileListing.items;
for(FileInfo fileInfo:items){
System.out.println(fileInfo.key);
}
} catch (QiniuException e) {
//捕获异常信息
Response r = e.response;
System.out.println(r.toString());
}
}
}