Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Paket oluşturma (Java SDK V1)

Son Güncelleme:Oct 01, 2026

Paket, nesneleri depolamak için kullanılan bir kapsayıcıdır. Tüm nesneler bir pakette depolanmalıdır. Bu konuda paket oluşturma adımları açıklanmaktadır.

Notlar

  • Bu konuda China (Hangzhou) bölgesinin genel uç noktası kullanılmaktadır. Aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'e erişmek için dahili uç noktayı kullanın. Desteklenen bölgeler ve uç noktalar hakkında ayrıntılı bilgi için bkz. Bölgeler ve uç noktalar.

  • Bu konuda kimlik doğrulama bilgileri ortam değişkenlerinden alınır. Kimlik doğrulama bilgilerinin yapılandırılması hakkında daha fazla bilgi için bkz. Erişim kimlik bilgilerini yapılandırma.

  • Bu konuda bir OSS uç noktası kullanılarak OSSClient örneği oluşturulmaktadır. Özel etki alanı kullanımı veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. İstemci yapılandırması.

  • 13 Ekim 2025 tarihinde saat 10:00:00'dan (UTC+8) itibaren OSS, tüm bölgelerde API işlemleri çağrılarak veya OSS SDK'ları ya da ossutil kullanılarak oluşturulan paketler için Genel erişimi engelleme özelliğini varsayılan olarak kademeli şekilde etkinleştirir. Değişikliğin her bölgede yürürlüğe gireceği zaman için bkz. Duyuru. Bu özellik etkinleştirildikten sonra public-read veya public-read-write ACL'leri ile genel erişime izin veren paket ilkeleri dahil olmak üzere genel erişim izinleri verilemez. İş süreçleriniz genel erişim gerektiriyorsa paket oluşturulduktan sonra genel erişimi engelleme özelliğini devre dışı bırakabilirsiniz.

İzinler

Varsayılan olarak bir Alibaba Cloud hesabı tam yetkilere sahiptir. Bir Alibaba Cloud hesabı altındaki RAM kullanıcıları veya RAM rolleri varsayılan olarak herhangi bir izne sahip değildir. Alibaba Cloud hesabı veya hesap yöneticisi, işlem izinlerini RAM ilkeleri veya Paket İlkesi aracılığıyla vermelidir.

API

Eylem

Açıklama

PutBucket

oss:PutBucket

Bir paket oluşturur.

oss:PutBucketAcl

Paket oluşturulduktan sonra paket ACL'sini değiştirmek için bu izin gereklidir.

Örnek kod

Aşağıdaki kod, examplebucket adlı bir paketin nasıl oluşturulacağını gösterir.

import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;

public class Demo {

    public static void main(String[] args) throws Exception {
        // Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set Endpoint to https://oss-cn-hangzhou.aliyuncs.com.
        String endpoint = "yourEndpoint";
        // Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the bucket name.
        String bucketName = "examplebucket";
        // Specify the resource group ID. If you do not specify a resource group ID, the bucket is added to the default resource group.
        //String rsId = "rg-aek27tc****";
        // Specify the region where the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set Region to cn-hangzhou.
        String region = "cn-hangzhou";
        
        // Create an OSSClient instance.
        // After an OSSClient instance is no longer used, call the shutdown method to release resources.
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);        
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)               
        .build();

        try {
            // Create a bucket and enable the hierarchical namespace feature.
            CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName).withHnsStatus(HnsStatus.Enabled);
            // If you want to specify the storage class, ACL, and data redundancy type when you create a bucket, see the following code.
            // The following code provides an example of how to set the storage class to Standard.
            createBucketRequest.setStorageClass(StorageClass.Standard);
            // The default data redundancy type is LRS, which is specified as DataRedundancyType.LRS. If you want to set the data redundancy type to ZRS, set the value to DataRedundancyType.ZRS.
            createBucketRequest.setDataRedundancyType(DataRedundancyType.ZRS);
            // Set the ACL of the bucket to public-read. The default ACL is private.
            createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
            // When you create a bucket in a region that supports resource groups, you can assign the bucket to a resource group.
            //createBucketRequest.setResourceGroupId(rsId);

            // Create the bucket.
            ossClient.createBucket(createBucketRequest);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

İlgili konular

  • Paket oluşturmaya ilişkin eksiksiz örnek kod için GitHub örneğine bakın.

  • Paket oluşturma API işlemi hakkında daha fazla bilgi için bkz. PutBucket.