SDK 提供了ClassSwitch
方法用以实现文件存储类型转换,存储类型概念详见存储类型。
ClassSwitch
方法请求的 US3 API 为 ClassSwitch ,具体详见 ClassSwitch API文档。
说明:
- 目前 ClassSwitch 仅支持由热向冷转换,即 STANDARD -> IA,IA -> ARCHIVE 和 STANDARD -> ARCHIVE
- 如需要将冷文件向热转换,重新上传即可
标准转低频
示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
public class SwitchStorageTypeSample {
private static final String TAG = "SwitchStorageTypeSample";
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
public static void main(String[] args) {
String bucketName = "";
String keyName = "";
/**
* 目前支持3种存储类型均在StorageType中标明
*/
switchStorageType(bucketName, keyName, StorageType.STANDARD);
}
public static void switchStorageType(String bucketName, String keyName, String storageType) {
try {
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.switchStorageType(bucketName, keyName)
.turnTypeTo(storageType)
.execute();
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
} catch (UfileClientException e) {
e.printStackTrace();
} catch (UfileServerException e) {
e.printStackTrace();
}
}
public static void switchStorageTypeAsync(String bucketName, String keyName, String storageType) {
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.switchStorageType(bucketName, keyName)
.turnTypeTo(storageType)
.executeAsync(new UfileCallback<BaseObjectResponseBean>() {
@Override
public void onResponse(BaseObjectResponseBean response) {
JLog.D(TAG, String.format("[res] = %s", (response == null ? "null" : response.toString())));
}
@Override
public void onError(Request request, ApiError error, UfileErrorBean response) {
JLog.D(TAG, String.format("[error] = %s\n[info] = %s",
(error == null ? "null" : error.toString()),
(response == null ? "null" : response.toString())));
}
});
}
}
PREVIOUS比较本地文件和远程文件etag
NEXT获取文件基本信息