SDK 提供DeleteFile
方法用以删除文件,完整代码详见 。
DeleteFile
方法请求的 US3 API 为 DeleteFile,具体详见DeleteFile API文档。
删除
示例如下:
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
public class DeleteObjectSample {
private static final String TAG = "DeleteObjectSample";
private static ObjectConfig config = new ObjectConfig("cn-sh2", "ufileos.com");
public static void main(String[] args) {
String keyName = "";
String bucketName = "";
execute(keyName, bucketName);
}
public static void execute(String keyName, String bucketName) {
try {
BaseObjectResponseBean response = UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.deleteObject(keyName, bucketName)
.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 executeAsync(String keyName, String bucketName) {
UfileClient.object(Constants.OBJECT_AUTHORIZER, config)
.deleteObject(keyName, bucketName)
.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())));
}
});
}
}
错误码
HTTP 状态码 | RetCode | ErrMsg | 描述 |
---|---|---|---|
400 | -148653 | bucket not exists | 存储空间不存在 |
400 | -15036 | check md5 failed | MD5校验失败 |
401 | -148643 | no authorization found | 上传凭证错误 |
403 | -148643 | invalid signature | API公私钥错误 |
404 | -148654 | file not exist | 文件不存在 |