全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

修改文件存储类型(Java)

最近更新时间:2025-09-29 18:50:26

  • 方法一,复制文件但不修改名称仅修改存储类型

/**
 * 设置对象的存储类型
 */
public void setObjectStorageClassWhenCopy() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        CopyObjectRequest request = new CopyObjectRequest("bucketName", "objectKey", "bucketName", "objectKey");
        request.setStorageClass(StorageClass.Standard);
        // 发起请求,设置对象的存储类型
        CopyResult copyResult = ks3Client.copyObject(request);
        System.out.println("ETag: " + copyResult.getETag());
        System.out.println("CRC64: " + copyResult.getCrc64Ecma());
        System.out.println("Last Modified: " + copyResult.getLastModified());
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 关闭 Ks3Client
        ks3Client.shutdown();
    }
}
  • 方法二,使用 putObjectStorageClass 方法(1.4.0 版本及之后)

/**
 * 设置对象的存储类型
 * 本质上仍是 copy object,与上面的方式相同
 * 1.4.0 及之后版本支持
 */
public void putObjectStorageClass() {
    // 初始化 Ks3Client,参见“初始化”文档
    Ks3Client ks3Client = initKs3Client();

    try {
        // 发起请求,设置对象的存储类型
        CopyResult copyResult = ks3Client.putObjectStorageClass("bucketName", "objectKey", StorageClass.Standard);
        System.out.println("ETag: " + copyResult.getETag());
        System.out.println("CRC64: " + copyResult.getCrc64Ecma());
        System.out.println("Last Modified: " + copyResult.getLastModified());
    } catch (Ks3ServiceException e) {
        System.out.println("Ks3ServiceException occurred, which means the request was made to KS3, but KS3 returned an error response for some reason.");
        System.out.println("Error Message: " + e.getErrorMessage());
        System.out.println("Error Code: " + e.getErrorCode());
        System.out.println("Request ID: " + e.getRequestId());
    } catch (Ks3ClientException e) {
        System.out.println("Ks3ClientException occurred, which means the client encountered an internal error while trying to communicate with KS3.");
        System.out.println("Error Message: " + e.getMessage());
    } finally {
        // 关闭 Ks3Client
        ks3Client.shutdown();
    }
}

文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈