文档中心 对象存储(KS3) SDK Android(新) 管理文件(Android). 管理对象标签(Android)

管理对象标签(Android)

最近更新时间:2024-12-27 16:20:42

设置对象标签

Ks3Client client = new Ks3Client("AccessKeyId", "SecretAccessKey", getApplicationContext());
client.setEndpoint("ks3-cn-beijing.ksyuncs.com");
ObjectTagging objectTagging = new ObjectTagging();
objectTagging.addObjectTag("tagA", "A");
PutObjectTaggingRequest request = new PutObjectTaggingRequest("bucketName", "objectKey", objectTagging);
client.putObjectTag(request, new PutObjectTaggingResponseHandler() {
    @Override
    public void onSuccess(PutObjectTaggingRequest request, PutObjectTaggingResult result) {
        Log.i("Put Object Tagging", "Status Code: " + result.getStatusCode());
    }

    @Override
    public void onFailure(PutObjectTaggingRequest request, Ks3ClientException clientException, Ks3ServiceException serviceException) {
        if (clientException != null) {
            Log.e("Put Object Tagging", "ClientException: " + clientException.getMessage());
        }
        if (serviceException != null) {
            Log.e("Put Object Tagging", "ServiceException: " + serviceException.getMessage());
        }
    }
});

获取对象标签

Ks3Client client = new Ks3Client("AccessKeyId", "SecretAccessKey", getApplicationContext());
client.setEndpoint("ks3-cn-beijing.ksyuncs.com");
GetObjectTaggingRequest request = new GetObjectTaggingRequest("bucketName", "objectKey");
client.getObjectTag(request, new GetObjectTaggingResponseHandler() {
    @Override
    public void onSuccess(GetObjectTaggingRequest request, GetObjectTaggingResult result) {
        Log.i("Get Object Tagging", "Status Code: " + result.getStatusCode());
        Log.i("Get Object Tagging", "Tagging: " + result.getTagging().toString());
    }

    @Override
    public void onFailure(GetObjectTaggingRequest request, Ks3ClientException clientException, Ks3ServiceException serviceException) {
        if (clientException != null) {
            Log.e("Get Object Tagging", "ClientException: " + clientException.getMessage());
        }
        if (serviceException != null) {
            Log.e("Get Object Tagging", "ServiceException: " + serviceException.getMessage());
        }
    }
});

删除对象标签

Ks3Client client = new Ks3Client("AccessKeyId", "SecretAccessKey", getApplicationContext());
client.setEndpoint("ks3-cn-beijing.ksyuncs.com");
DeleteObjectTaggingRequest request = new DeleteObjectTaggingRequest("bucketName", "objectKey");
client.deleteObjectTag(request, new DeleteObjectTaggingResponseHandler() {
    @Override
    public void onSuccess(DeleteObjectTaggingRequest request, DeleteObjectTaggingResult result) {
        Log.i("Delete Object Tagging", "Status Code: " + result.getStatusCode());
    }

    @Override
    public void onFailure(DeleteObjectTaggingRequest request, Ks3ClientException clientException, Ks3ServiceException serviceException) {
        if (clientException != null) {
            Log.e("Delete Object Tagging", "ClientException: " + clientException.getMessage());
        }
        if (serviceException != null) {
            Log.e("Delete Object Tagging", "ServiceException: " + serviceException.getMessage());
        }
    }
});

上一篇:列举文件(Android)
下一篇:Android(旧)
以上内容是否对您有帮助?
有帮助
没帮助