//构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
String accessKey = "your access key";
String secretKey = "your secret key";
String bucket = "your bucket name";
Auth auth = Auth.create(accessKey, secretKey);
BucketManager bucketManager = new BucketManager(auth, cfg);
try {
//单次批量请求的文件数量不得超过1000
String[] keyList = new String[]{
"qiniu.jpg",
"qiniu.mp4",
"qiniu.png",
};
BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
batchOperations.addStatOps(bucket, keyList);
Response response = bucketManager.batch(batchOperations);
BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);
for (int i = 0; i < keyList.length; i++) {
BatchStatus status = batchStatusList[i];
String key = keyList[i];
System.out.print(key+"\t");
if (status.code == 200) {
//文件存在
System.out.println(status.data.hash);
System.out.println(status.data.mimeType);
System.out.println(status.data.fsize);
System.out.println(status.data.putTime);
} else {
System.out.println(status.data.error);
}
}
} catch (QiniuException ex) {
System.err.println(ex.response.toString());
}
//构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
String accessKey = "your access key";
String secretKey = "your secret key";
String bucket = "your bucket name";
Auth auth = Auth.create(accessKey, secretKey);
BucketManager bucketManager = new BucketManager(auth, cfg);
try {
//单次批量请求的文件数量不得超过1000
HashMap<String, String> keyMimeMap = new HashMap<>();
keyMimeMap.put("qiniu.jpg", "image/jpg");
keyMimeMap.put("qiniu.png", "image/png");
keyMimeMap.put("qiniu.mp4", "video/mp4");
BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
//添加指令
for (Map.Entry<String, String> entry : keyMimeMap.entrySet()) {
String key = entry.getKey();
String newMimeType = entry.getValue();
batchOperations.addChgmOp(bucket, key, newMimeType);
}
Response response = bucketManager.batch(batchOperations);
BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);
int index = 0;
for (Map.Entry<String, String> entry : keyMimeMap.entrySet()) {
String key = entry.getKey();
System.out.print(key + "\t");
BatchStatus status = batchStatusList[index];
if (status.code == 200) {
System.out.println("change mime success");
} else {
System.out.println(status.data.error);
}
index += 1;
}
} catch (QiniuException ex) {
System.err.println(ex.response.toString());
}
//构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
String accessKey = "your access key";
String secretKey = "your secret key";
String bucket = "your bucket name";
Auth auth = Auth.create(accessKey, secretKey);
BucketManager bucketManager = new BucketManager(auth, cfg);
try {
//单次批量请求的文件数量不得超过1000
String[] keyList = new String[]{
"qiniu.jpg",
"qiniu.mp4",
"qiniu.png",
};
BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
batchOperations.addDeleteOp(bucket, keyList);
Response response = bucketManager.batch(batchOperations);
BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);
for (int i = 0; i < keyList.length; i++) {
BatchStatus status = batchStatusList[i];
String key = keyList[i];
System.out.print(key + "\t");
if (status.code == 200) {
System.out.println("delete success");
} else {
System.out.println(status.data.error);
}
}
} catch (QiniuException ex) {
System.err.println(ex.response.toString());
}

//构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
String accessKey = "your access key";
String secretKey = "your secret key";
String bucket = "your bucket name";
Auth auth = Auth.create(accessKey, secretKey);
BucketManager bucketManager = new BucketManager(auth, cfg);
try {
//单次批量请求的文件数量不得超过1000
String[] keyList = new String[]{
"qiniu.jpg",
"qiniu.mp4",
"qiniu.png",
};
BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations();
for (String key : keyList) {
batchOperations.addMoveOp(bucket, key, bucket, key + "_move");
}
Response response = bucketManager.batch(batchOperations);
BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[].class);
for (int i = 0; i < keyList.length; i++) {
BatchStatus status = batchStatusList[i];
String key = keyList[i];
System.out.print(key + "\t");
if (status.code == 200) {
System.out.println("move success");
} else {
System.out.println(status.data.error);
}
}
} catch (QiniuException ex) {
System.err.println(ex.response.toString());
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-118827-4.html
我
打个比方