diff --git a/docs/obs_3rd_party/java_sdk/ALL_META.TXT.json b/docs/obs_3rd_party/java_sdk/ALL_META.TXT.json new file mode 100644 index 000000000..013f1ec15 --- /dev/null +++ b/docs/obs_3rd_party/java_sdk/ALL_META.TXT.json @@ -0,0 +1,2775 @@ +[ + { + "dockw":"Developer Guide (Java SDK)" + }, + { + "uri":"obs_21_0101.html", + "node_id":"obs_21_0101.xml", + "product_code":"obs", + "code":"1", + "des":"This section describes version compatibility and important notes about Object Storage Service (OBS) SDK for Java.Recommended JDK versions: JDK 8 or laterThird-party depen", + "doc_type":"sdk-java-devg", + "kw":"Before You Start,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Before You Start", + "githuburl":"" + }, + { + "uri":"obs_21_0002.html", + "node_id":"obs_21_0002.xml", + "product_code":"obs", + "code":"2", + "des":"Table 1 lists the bucket-related APIs.Table 2lists object-related APIs.Table 3 lists the APIs related to temporarily authorized access.Table 4 lists the APIs related to v", + "doc_type":"sdk-java-devg", + "kw":"API Overview,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"API Overview", + "githuburl":"" + }, + { + "uri":"obs_21_0102.html", + "node_id":"obs_21_0102.xml", + "product_code":"obs", + "code":"3", + "des":"Before using OBS SDK for Java to access OBS, you need to prepare the service and development environments. To prepare the service environment, you will need an account an", + "doc_type":"sdk-java-devg", + "kw":"Preparations,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Preparations", + "githuburl":"" + }, + { + "uri":"obs_21_0001.html", + "node_id":"obs_21_0001.xml", + "product_code":"obs", + "code":"4", + "des":"Latest version of OBS Java SDK: DownloadYou can download the source code of SDK for Java and compile the source code to create a JAR package. Before using this method, en", + "doc_type":"sdk-java-devg", + "kw":"SDK Download and Installation,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"SDK Download and Installation", + "githuburl":"" + }, + { + "uri":"obs_21_0100.html", + "node_id":"obs_21_0100.xml", + "product_code":"obs", + "code":"5", + "des":"This section introduces how to use OBS SDK for Java to perform some basic actions, such as creating a bucket, and uploading, downloading, listing, and deleting objects.En", + "doc_type":"sdk-java-devg", + "kw":"Getting Started,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Getting Started", + "githuburl":"" + }, + { + "uri":"obs_21_0200.html", + "node_id":"obs_21_0200.xml", + "product_code":"obs", + "code":"6", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Initialization", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Initialization", + "githuburl":"" + }, + { + "uri":"obs_21_0201.html", + "node_id":"obs_21_0201.xml", + "product_code":"obs", + "code":"7", + "des":"After the SDK is installed, you need to create and configure an OBS client and configure the logging for the SDK to complete the initialization.", + "doc_type":"sdk-java-devg", + "kw":"Overview,Initialization,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_0202.html", + "node_id":"obs_21_0202.xml", + "product_code":"obs", + "code":"8", + "des":"This section describes how to create and configure an OBS client. If you already have a client, skip this section and obtain the API details by referring to API Overview.", + "doc_type":"sdk-java-devg", + "kw":"Creating and Configuring an OBS Client,Initialization,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Creating and Configuring an OBS Client", + "githuburl":"" + }, + { + "uri":"obs_21_0204.html", + "node_id":"obs_21_0204.xml", + "product_code":"obs", + "code":"9", + "des":"OBS SDK for Java offers logging based on the open-source Apache Log4j 2 library. By default, the SDK stores WARN log files to the directory specified by the JDK system va", + "doc_type":"sdk-java-devg", + "kw":"Configuring SDK Logging,Initialization,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring SDK Logging", + "githuburl":"" + }, + { + "uri":"obs_21_0400.html", + "node_id":"obs_21_0400.xml", + "product_code":"obs", + "code":"10", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Bucket Management", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Bucket Management", + "githuburl":"" + }, + { + "uri":"obs_21_0401.html", + "node_id":"obs_21_0401.xml", + "product_code":"obs", + "code":"11", + "des":"This API creates an OBS bucket. Buckets are containers for storing objects (files uploaded to OBS) in OBS.When creating a bucket, you can also configure parameters such a", + "doc_type":"sdk-java-devg", + "kw":"Creating a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Creating a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0402.html", + "node_id":"obs_21_0402.xml", + "product_code":"obs", + "code":"12", + "des":"OBS buckets are containers for storing objects you upload to OBS. This API returns a list of all buckets that meet the specified conditions in all regions of the current ", + "doc_type":"sdk-java-devg", + "kw":"Obtaining a Bucket List,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining a Bucket List", + "githuburl":"" + }, + { + "uri":"obs_21_0403.html", + "node_id":"obs_21_0403.xml", + "product_code":"obs", + "code":"13", + "des":"This API deletes an empty bucket. You can delete buckets you no longer use to free up space. The name of a deleted bucket can be reused for another bucket at least 30 min", + "doc_type":"sdk-java-devg", + "kw":"Deleting a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0404.html", + "node_id":"obs_21_0404.xml", + "product_code":"obs", + "code":"14", + "des":"This API checks whether a bucket exists. If an HTTP status code 200 is returned, the bucket exists. If 404 is returned, the bucket does not exist.To check whether a bucke", + "doc_type":"sdk-java-devg", + "kw":"Checking Whether a Bucket Exists,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Checking Whether a Bucket Exists", + "githuburl":"" + }, + { + "uri":"obs_21_0405.html", + "node_id":"obs_21_0405.xml", + "product_code":"obs", + "code":"15", + "des":"This API returns information about a bucket, including the storage class, region, CORS rules, and redundancy policy.To obtain bucket metadata, you must be the bucket owne", + "doc_type":"sdk-java-devg", + "kw":"Obtaining Bucket Metadata,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining Bucket Metadata", + "githuburl":"" + }, + { + "uri":"obs_21_0406.html", + "node_id":"obs_21_0406.xml", + "product_code":"obs", + "code":"16", + "des":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "doc_type":"sdk-java-devg", + "kw":"Setting a Bucket ACL,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Setting a Bucket ACL", + "githuburl":"" + }, + { + "uri":"obs_21_0412.html", + "node_id":"obs_21_0412.xml", + "product_code":"obs", + "code":"17", + "des":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "doc_type":"sdk-java-devg", + "kw":"Obtaining a Bucket ACL,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining a Bucket ACL", + "githuburl":"" + }, + { + "uri":"obs_21_0407.html", + "node_id":"obs_21_0407.xml", + "product_code":"obs", + "code":"18", + "des":"OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control ca", + "doc_type":"sdk-java-devg", + "kw":"Configuring a Bucket Policy,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring a Bucket Policy", + "githuburl":"" + }, + { + "uri":"obs_21_0413.html", + "node_id":"obs_21_0413.xml", + "product_code":"obs", + "code":"19", + "des":"OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control ca", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Policy of a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Policy of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0414.html", + "node_id":"obs_21_0414.xml", + "product_code":"obs", + "code":"20", + "des":"OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control ca", + "doc_type":"sdk-java-devg", + "kw":"Deleting a Bucket Policy,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting a Bucket Policy", + "githuburl":"" + }, + { + "uri":"obs_21_0408.html", + "node_id":"obs_21_0408.xml", + "product_code":"obs", + "code":"21", + "des":"This API returns the region where a bucket is located.To obtain the region of a bucket, you must be the bucket owner or have the required permission (obs:bucket:GetBucket", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Region of a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Region of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0409.html", + "node_id":"obs_21_0409.xml", + "product_code":"obs", + "code":"22", + "des":"This API returns the storage information of a bucket, including the number of objects and the space occupied by the objects in the bucket.OBS measures bucket storage stat", + "doc_type":"sdk-java-devg", + "kw":"Obtaining Storage Information of a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining Storage Information of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0410.html", + "node_id":"obs_21_0410.xml", + "product_code":"obs", + "code":"23", + "des":"A quota limits the maximum capacity allowed in a bucket. By default, there is no limit on the storage capacity of the entire OBS system or a single bucket, and any number", + "doc_type":"sdk-java-devg", + "kw":"Configuring a Storage Quota,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring a Storage Quota", + "githuburl":"" + }, + { + "uri":"obs_21_0415.html", + "node_id":"obs_21_0415.xml", + "product_code":"obs", + "code":"24", + "des":"This API returns the storage quota (upper limit of the storage capacity) of a bucket. If the quota is 0, there is no upper limit on the bucket capacity.A bucket quota mus", + "doc_type":"sdk-java-devg", + "kw":"Obtaining a Bucket Storage Quota,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining a Bucket Storage Quota", + "githuburl":"" + }, + { + "uri":"obs_21_0411.html", + "node_id":"obs_21_0411.xml", + "product_code":"obs", + "code":"25", + "des":"This API configures a storage class for a bucket. If you do not specify a storage class when uploading or copying an object, or initiating a multipart upload, the object ", + "doc_type":"sdk-java-devg", + "kw":"Configuring a Storage Class for a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring a Storage Class for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0416.html", + "node_id":"obs_21_0416.xml", + "product_code":"obs", + "code":"26", + "des":"This API returns the storage class of a bucket.To obtain a bucket's storage class, you must be the bucket owner or have the required permission (obs:bucket:GetBucketStora", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Storage Class of a Bucket,Bucket Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Storage Class of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_0421.html", + "node_id":"obs_21_0421.xml", + "product_code":"obs", + "code":"27", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Bucket Inventory", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Bucket Inventory", + "githuburl":"" + }, + { + "uri":"obs_21_0417.html", + "node_id":"obs_21_0417.xml", + "product_code":"obs", + "code":"28", + "des":"This API configures an inventory rule for the bucket. With this API, object information in a bucket (source) is regularly listed and saved as CSV files. These files are t", + "doc_type":"sdk-java-devg", + "kw":"Configuring an Inventory Rule,Bucket Inventory,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring an Inventory Rule", + "githuburl":"" + }, + { + "uri":"obs_21_0418.html", + "node_id":"obs_21_0418.xml", + "product_code":"obs", + "code":"29", + "des":"This API returns an inventory rule (identified by configurationId) for the bucket.To obtain a bucket inventory rule, you must be the bucket owner or have the required per", + "doc_type":"sdk-java-devg", + "kw":"Obtaining an Inventory Rule,Bucket Inventory,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining an Inventory Rule", + "githuburl":"" + }, + { + "uri":"obs_21_0419.html", + "node_id":"obs_21_0419.xml", + "product_code":"obs", + "code":"30", + "des":"This API returns a list of all inventory rules for the bucket.To list inventory rules for a bucket, you must be the bucket owner or have the required permission (obs:buck", + "doc_type":"sdk-java-devg", + "kw":"Listing Inventory Rules,Bucket Inventory,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Listing Inventory Rules", + "githuburl":"" + }, + { + "uri":"obs_21_0420.html", + "node_id":"obs_21_0420.xml", + "product_code":"obs", + "code":"31", + "des":"This API deletes an inventory rule (identified by configurationId) from the bucket.To delete a bucket inventory rule, you must be the bucket owner or have the required pe", + "doc_type":"sdk-java-devg", + "kw":"Deleting an Inventory Rule,Bucket Inventory,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting an Inventory Rule", + "githuburl":"" + }, + { + "uri":"obs_21_0600.html", + "node_id":"obs_21_0600.xml", + "product_code":"obs", + "code":"32", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Object Upload", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Object Upload", + "githuburl":"" + }, + { + "uri":"obs_21_0601.html", + "node_id":"obs_21_0601.xml", + "product_code":"obs", + "code":"33", + "des":"In OBS, objects are basic data units that users can perform operations on. OBS Java SDK provides abundant APIs for object upload in the following methods:StreamingFile-ba", + "doc_type":"sdk-java-devg", + "kw":"Overview,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_0602.html", + "node_id":"obs_21_0602.xml", + "product_code":"obs", + "code":"34", + "des":"This API uploads a local fileto OBS over the Internet. These files can be texts, images, videos, or any other type of files.You can upload texts, images, videos, or any o", + "doc_type":"sdk-java-devg", + "kw":"Uploading an Object - Streaming,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Uploading an Object - Streaming", + "githuburl":"" + }, + { + "uri":"obs_21_0603.html", + "node_id":"obs_21_0603.xml", + "product_code":"obs", + "code":"35", + "des":"This API uploads local filesto OBS over the Internet. The file to be uploaded can be of any type.To upload an object, you must be the bucket owner or have the required pe", + "doc_type":"sdk-java-devg", + "kw":"Uploading an Object - File-Based,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Uploading an Object - File-Based", + "githuburl":"" + }, + { + "uri":"obs_21_0604.html", + "node_id":"obs_21_0604.xml", + "product_code":"obs", + "code":"36", + "des":"This API returns the upload progress of a specified object.You can call PutObjectRequest.setProgressListener to obtain the upload progress.To obtain the upload progress, ", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Upload Progress,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Upload Progress", + "githuburl":"" + }, + { + "uri":"obs_21_0605.html", + "node_id":"obs_21_0605.xml", + "product_code":"obs", + "code":"37", + "des":"This API creates a folder in an existing bucket to manage data in OBS.OBS does not involve folders like in a file system. All elements in buckets are objects. To create a", + "doc_type":"sdk-java-devg", + "kw":"Creating a Folder,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Creating a Folder", + "githuburl":"" + }, + { + "uri":"obs_21_0606.html", + "node_id":"obs_21_0606.xml", + "product_code":"obs", + "code":"38", + "des":"This API configures metadata for an object when uploading it. Object metadata include the object length, MIME type, MD5 value (for verification), storage class, and custo", + "doc_type":"sdk-java-devg", + "kw":"Configuring Object Metadata,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Object Metadata", + "githuburl":"" + }, + { + "uri":"obs_21_0607.html", + "node_id":"obs_21_0607.xml", + "product_code":"obs", + "code":"39", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Multipart Upload", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_21_0614.html", + "node_id":"obs_21_0614.xml", + "product_code":"obs", + "code":"40", + "des":"You can upload large files using multipart upload. Multipart upload is applicable to many scenarios, including:Files to be uploaded are larger than 100 MB.The network con", + "doc_type":"sdk-java-devg", + "kw":"Multipart Upload Overview,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Multipart Upload Overview", + "githuburl":"" + }, + { + "uri":"obs_21_0615.html", + "node_id":"obs_21_0615.xml", + "product_code":"obs", + "code":"41", + "des":"This API initiates a multipart upload and returns a globally unique upload ID. You can use this upload ID in your subsequent requests including abortMultipartUpload, list", + "doc_type":"sdk-java-devg", + "kw":"Initiating a Multipart Upload,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Initiating a Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_21_0616.html", + "node_id":"obs_21_0616.xml", + "product_code":"obs", + "code":"42", + "des":"After a multipart upload is initiated, this API uploads a part to a specified bucket. In the upload request, the multipart upload ID must be included. Except for the part", + "doc_type":"sdk-java-devg", + "kw":"Uploading a Part,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Uploading a Part", + "githuburl":"" + }, + { + "uri":"obs_21_0617.html", + "node_id":"obs_21_0617.xml", + "product_code":"obs", + "code":"43", + "des":"This API assembles the uploaded parts to complete the multipart upload. Before performing this operation, you cannot download the uploaded data. When assembling parts, yo", + "doc_type":"sdk-java-devg", + "kw":"Assembling Parts,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Assembling Parts", + "githuburl":"" + }, + { + "uri":"obs_21_0618.html", + "node_id":"obs_21_0618.xml", + "product_code":"obs", + "code":"44", + "des":"Multipart upload is mainly used for large file upload or when the network connection is poor.You can use UploadPartRequest.setOffset and UploadPartRequest.setPartSize to ", + "doc_type":"sdk-java-devg", + "kw":"Code Example of a Multipart Upload,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Code Example of a Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_21_0619.html", + "node_id":"obs_21_0619.xml", + "product_code":"obs", + "code":"45", + "des":"This API aborts a multipart upload using the multipart upload ID.After a multipart upload is aborted, the upload ID cannot be used to upload any part. The storage occupie", + "doc_type":"sdk-java-devg", + "kw":"Aborting a Multipart Upload,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Aborting a Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_21_0620.html", + "node_id":"obs_21_0620.xml", + "product_code":"obs", + "code":"46", + "des":"This API lists the uploaded parts in a specified bucket. This request must contain the multipart upload ID.You can list the uploaded parts of a specified multipart upload", + "doc_type":"sdk-java-devg", + "kw":"Listing Uploaded Parts,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Listing Uploaded Parts", + "githuburl":"" + }, + { + "uri":"obs_21_0621.html", + "node_id":"obs_21_0621.xml", + "product_code":"obs", + "code":"47", + "des":"This API lists ongoing multipart uploads.Ongoing multipart uploads are the multipart uploads that have been initiated but have not been completed or aborted. A maximum of", + "doc_type":"sdk-java-devg", + "kw":"Listing Multipart Uploads,Multipart Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Listing Multipart Uploads", + "githuburl":"" + }, + { + "uri":"obs_21_0608.html", + "node_id":"obs_21_0608.xml", + "product_code":"obs", + "code":"48", + "des":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes. The object expiration time set using this API takes preced", + "doc_type":"sdk-java-devg", + "kw":"Configuring Lifecycle Rules,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Lifecycle Rules", + "githuburl":"" + }, + { + "uri":"obs_21_0609.html", + "node_id":"obs_21_0609.xml", + "product_code":"obs", + "code":"49", + "des":"This API uploads a file or folder to an existing OBS bucket. These files can be texts, images, videos, or any other type of files.The appendObject operation adds data to ", + "doc_type":"sdk-java-devg", + "kw":"Uploading an Object - Append,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Uploading an Object - Append", + "githuburl":"" + }, + { + "uri":"obs_21_0611.html", + "node_id":"obs_21_0611.xml", + "product_code":"obs", + "code":"50", + "des":"The resumable upload is an encapsulated and enhanced version of the multipart upload used for dealing with possible upload failures of large files when the network connec", + "doc_type":"sdk-java-devg", + "kw":"Uploading an Object - Resumable,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Uploading an Object - Resumable", + "githuburl":"" + }, + { + "uri":"obs_21_0612.html", + "node_id":"obs_21_0612.xml", + "product_code":"obs", + "code":"51", + "des":"This API uploads an object up to 5 GB to a specified bucket in HTML form.You can call ObsClient.createPostSignature to generate request parameters for a browser-based upl", + "doc_type":"sdk-java-devg", + "kw":"Uploading an Object - Browser-Based,Object Upload,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Uploading an Object - Browser-Based", + "githuburl":"" + }, + { + "uri":"obs_21_0700.html", + "node_id":"obs_21_0700.xml", + "product_code":"obs", + "code":"52", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Object Download", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Object Download", + "githuburl":"" + }, + { + "uri":"obs_21_0701.html", + "node_id":"obs_21_0701.xml", + "product_code":"obs", + "code":"53", + "des":"OBS Java SDK provides abundant APIs for object download in the following methods:Streaming DownloadPartial DownloadResumable download", + "doc_type":"sdk-java-devg", + "kw":"Overview,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_0702.html", + "node_id":"obs_21_0702.xml", + "product_code":"obs", + "code":"54", + "des":"When you call ObsClient.getObject, an instance of ObsObject will be returned. This instance contains the contents of the object such as its name, attributes, input stream", + "doc_type":"sdk-java-devg", + "kw":"Downloading an Object - Streaming,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Downloading an Object - Streaming", + "githuburl":"" + }, + { + "uri":"obs_21_0703.html", + "node_id":"obs_21_0703.xml", + "product_code":"obs", + "code":"55", + "des":"This API downloads partial data of an object by specifying a range. If the specified range is from 0 to 1,000, data from byte 0 to byte 1,000, 1,001 bytes in total, are r", + "doc_type":"sdk-java-devg", + "kw":"Downloading an Object - Range-Based,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Downloading an Object - Range-Based", + "githuburl":"" + }, + { + "uri":"obs_21_0704.html", + "node_id":"obs_21_0704.xml", + "product_code":"obs", + "code":"56", + "des":"This API returns the download progress of a specified object.You can call GetObjectRequest.setProgressInterval to obtain the download progress.To obtain the download prog", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Download Progress,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Download Progress", + "githuburl":"" + }, + { + "uri":"obs_21_0705.html", + "node_id":"obs_21_0705.xml", + "product_code":"obs", + "code":"57", + "des":"This API returns the objects that meet one or more conditions. If there are no objects that meet the specified conditions, an error is returned.To download an object, you", + "doc_type":"sdk-java-devg", + "kw":"Downloading an Object - Conditional,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Downloading an Object - Conditional", + "githuburl":"" + }, + { + "uri":"obs_21_0706.html", + "node_id":"obs_21_0706.xml", + "product_code":"obs", + "code":"58", + "des":"This API rewrites the following HTTP/HTTPS response headers when downloading an object: Content-Type, Content-Language, Expires, Cache-Control, Content-Disposition, and C", + "doc_type":"sdk-java-devg", + "kw":"Rewriting Response Headers,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Rewriting Response Headers", + "githuburl":"" + }, + { + "uri":"obs_21_0707.html", + "node_id":"obs_21_0707.xml", + "product_code":"obs", + "code":"59", + "des":"Object metadata is a set of key-value pairs that describe the object and is used for object management.This API returns the user-defined object metadata after the object ", + "doc_type":"sdk-java-devg", + "kw":"Obtaining User-defined Metadata,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining User-defined Metadata", + "githuburl":"" + }, + { + "uri":"obs_21_0708.html", + "node_id":"obs_21_0708.xml", + "product_code":"obs", + "code":"60", + "des":"Cold objects must first be restored before you can download them. Cold objects can be restored in either of the following ways.To restore a Cold object, you must be the b", + "doc_type":"sdk-java-devg", + "kw":"Restoring a Cold Object,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Restoring a Cold Object", + "githuburl":"" + }, + { + "uri":"obs_21_0709.html", + "node_id":"obs_21_0709.xml", + "product_code":"obs", + "code":"61", + "des":"Downloading large files often fails due to an unstable network or program breakdown. It is a waste of resources to download files again. Moreover, the restarted download ", + "doc_type":"sdk-java-devg", + "kw":"Downloading an Object - Resumable,Object Download,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Downloading an Object - Resumable", + "githuburl":"" + }, + { + "uri":"obs_21_0800.html", + "node_id":"obs_21_0800.xml", + "product_code":"obs", + "code":"62", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Object Management", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Object Management", + "githuburl":"" + }, + { + "uri":"obs_21_0806.html", + "node_id":"obs_21_0806.xml", + "product_code":"obs", + "code":"63", + "des":"Object metadata is a set of name-value pairs that describe the object and is used for object management.Currently, only the system-defined metadata is supported.There are", + "doc_type":"sdk-java-devg", + "kw":"Configuring Object Metadata,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Object Metadata", + "githuburl":"" + }, + { + "uri":"obs_21_0801.html", + "node_id":"obs_21_0801.xml", + "product_code":"obs", + "code":"64", + "des":"Object metadata is a set of name-value pairs that describe the object and is used for object management.Users with the READ permission on objects can send HEAD requests t", + "doc_type":"sdk-java-devg", + "kw":"Obtaining Object Metadata,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining Object Metadata", + "githuburl":"" + }, + { + "uri":"obs_21_0802.html", + "node_id":"obs_21_0802.xml", + "product_code":"obs", + "code":"65", + "des":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "doc_type":"sdk-java-devg", + "kw":"Configuring an Object ACL,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring an Object ACL", + "githuburl":"" + }, + { + "uri":"obs_21_0808.html", + "node_id":"obs_21_0808.xml", + "product_code":"obs", + "code":"66", + "des":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "doc_type":"sdk-java-devg", + "kw":"Obtaining an Object ACL,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining an Object ACL", + "githuburl":"" + }, + { + "uri":"obs_21_0803.html", + "node_id":"obs_21_0803.xml", + "product_code":"obs", + "code":"67", + "des":"This API lists some or all of the objects in a bucket. You can use parameters such as the prefix, number of returned objects, and start position to list objects that meet", + "doc_type":"sdk-java-devg", + "kw":"Listing Objects,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Listing Objects", + "githuburl":"" + }, + { + "uri":"obs_21_0804.html", + "node_id":"obs_21_0804.xml", + "product_code":"obs", + "code":"68", + "des":"This API deletes objects from a specific bucket.To delete an object, you must be the bucket owner or have the required permission (obs:object:DeleteObject in IAM or Delet", + "doc_type":"sdk-java-devg", + "kw":"Deleting an Object,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting an Object", + "githuburl":"" + }, + { + "uri":"obs_21_0809.html", + "node_id":"obs_21_0809.xml", + "product_code":"obs", + "code":"69", + "des":"This API deletes objects in batches from a specific bucket. Deleted objects cannot be recovered.In a batch delete operation, OBS concurrently deletes the specified object", + "doc_type":"sdk-java-devg", + "kw":"Batch Deleting Objects,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Batch Deleting Objects", + "githuburl":"" + }, + { + "uri":"obs_21_0805.html", + "node_id":"obs_21_0805.xml", + "product_code":"obs", + "code":"70", + "des":"This API copies an object stored in OBS to another path, with a copy created during the process. You can create a copy of an object up to 5 GB in a single operation.To co", + "doc_type":"sdk-java-devg", + "kw":"Copying an Object,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Copying an Object", + "githuburl":"" + }, + { + "uri":"obs_21_0810.html", + "node_id":"obs_21_0810.xml", + "product_code":"obs", + "code":"71", + "des":"This API allows you to upload a part by copying an object or part of this object.You can call ObsClient.copyPart to copy parts.To copy an object, you must be the bucket o", + "doc_type":"sdk-java-devg", + "kw":"Copying an Object - Multipart,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Copying an Object - Multipart", + "githuburl":"" + }, + { + "uri":"obs_21_0807.html", + "node_id":"obs_21_0807.xml", + "product_code":"obs", + "code":"72", + "des":"This API checks whether an object exists. If the returned HTTP status code is 200, the object exists. If the returned HTTP status code is 404, the object or bucket does n", + "doc_type":"sdk-java-devg", + "kw":"Checking Whether an Object Exists,Object Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Checking Whether an Object Exists", + "githuburl":"" + }, + { + "uri":"obs_21_0900.html", + "node_id":"obs_21_0900.xml", + "product_code":"obs", + "code":"73", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Temporarily Authorized Access", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Temporarily Authorized Access", + "githuburl":"" + }, + { + "uri":"obs_21_0901.html", + "node_id":"obs_21_0901.xml", + "product_code":"obs", + "code":"74", + "des":"ObsClient allows you to create a URL with Query parameters that carry authentication information by specifying the AK and SK, HTTP method, and request parameters. You can", + "doc_type":"sdk-java-devg", + "kw":"Accessing OBS Using a Signed URL,Temporarily Authorized Access,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Accessing OBS Using a Signed URL", + "githuburl":"" + }, + { + "uri":"obs_21_1000.html", + "node_id":"obs_21_1000.xml", + "product_code":"obs", + "code":"75", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Versioning", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Versioning", + "githuburl":"" + }, + { + "uri":"obs_21_1001.html", + "node_id":"obs_21_1001.xml", + "product_code":"obs", + "code":"76", + "des":"You can use versioning to store multiple versions of an object in a bucket.When versioning is enabled for a bucket, OBS keeps multiple versions of an object in the bucket", + "doc_type":"sdk-java-devg", + "kw":"Overview,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1002.html", + "node_id":"obs_21_1002.xml", + "product_code":"obs", + "code":"77", + "des":"You can enable versioning to automatically maintain previous versions of an object. When versioning is enabled, you can access earlier versions of an object to recover yo", + "doc_type":"sdk-java-devg", + "kw":"Configuring Versioning for a Bucket,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Versioning for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_1003.html", + "node_id":"obs_21_1003.xml", + "product_code":"obs", + "code":"78", + "des":"You can enable versioning to automatically maintain previous versions of an object. When versioning is enabled, you can access earlier versions of an object to recover yo", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Versioning Status of a Bucket,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Versioning Status of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_1004.html", + "node_id":"obs_21_1004.xml", + "product_code":"obs", + "code":"79", + "des":"You can call ObsClient.getObject to obtain an object version by specifying the version ID (versionId).To download an object, you must be the bucket owner or have the requ", + "doc_type":"sdk-java-devg", + "kw":"Obtaining an Object Version,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining an Object Version", + "githuburl":"" + }, + { + "uri":"obs_21_1005.html", + "node_id":"obs_21_1005.xml", + "product_code":"obs", + "code":"80", + "des":"This API copies an object version in a specified bucket.You can call ObsClient.copyObject to copy an object version by specifying the version ID (versionId).To copy an ob", + "doc_type":"sdk-java-devg", + "kw":"Copying an Object Version,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Copying an Object Version", + "githuburl":"" + }, + { + "uri":"obs_21_1006.html", + "node_id":"obs_21_1006.xml", + "product_code":"obs", + "code":"81", + "des":"This API downloads a Cold object. To download such an object, you must restore it first. For the options for the restore speed, see Table 3.You can call ObsClient.restore", + "doc_type":"sdk-java-devg", + "kw":"Restoring a Specific Cold Object Version,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Restoring a Specific Cold Object Version", + "githuburl":"" + }, + { + "uri":"obs_21_1007.html", + "node_id":"obs_21_1007.xml", + "product_code":"obs", + "code":"82", + "des":"This API lists some or all of the object versions in a bucket. When listing the object versions, you can specify the criteria such as the prefix, number, and start positi", + "doc_type":"sdk-java-devg", + "kw":"Listing Object Versions,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Listing Object Versions", + "githuburl":"" + }, + { + "uri":"obs_21_1008.html", + "node_id":"obs_21_1008.xml", + "product_code":"obs", + "code":"83", + "des":"OBS allows the control of access permissions for objects. By default, only object creators have the read and write permissions on the object. You can set access control p", + "doc_type":"sdk-java-devg", + "kw":"Setting an ACL for an Object Version,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Setting an ACL for an Object Version", + "githuburl":"" + }, + { + "uri":"obs_21_1010.html", + "node_id":"obs_21_1010.xml", + "product_code":"obs", + "code":"84", + "des":"OBS allows the control of access permissions for objects. By default, only object creators have the read and write permissions on the object. You can call an ACL API to m", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the ACL of an Object Version,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the ACL of an Object Version", + "githuburl":"" + }, + { + "uri":"obs_21_1009.html", + "node_id":"obs_21_1009.xml", + "product_code":"obs", + "code":"85", + "des":"This API deletes an object from a specific bucket.You can call ObsClient.deleteObject to pass a version ID (versionId) to delete an object version.To delete an object, yo", + "doc_type":"sdk-java-devg", + "kw":"Deleting an Object Version,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting an Object Version", + "githuburl":"" + }, + { + "uri":"obs_21_1011.html", + "node_id":"obs_21_1011.xml", + "product_code":"obs", + "code":"86", + "des":"This API deletes objects in batches from a specific bucket. Deleted objects cannot be recovered.In a batch delete operation, OBS concurrently deletes the specified object", + "doc_type":"sdk-java-devg", + "kw":"Batch Deleting Object Versions,Versioning,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Batch Deleting Object Versions", + "githuburl":"" + }, + { + "uri":"obs_21_1100.html", + "node_id":"obs_21_1100.xml", + "product_code":"obs", + "code":"87", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Lifecycle Management", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Lifecycle Management", + "githuburl":"" + }, + { + "uri":"obs_21_1101.html", + "node_id":"obs_21_1101.xml", + "product_code":"obs", + "code":"88", + "des":"OBS allows you to set lifecycle rules for buckets to automatically transition the storage class of an object or delete expired objects, to effectively use storage feature", + "doc_type":"sdk-java-devg", + "kw":"Overview,Lifecycle Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1102.html", + "node_id":"obs_21_1102.xml", + "product_code":"obs", + "code":"89", + "des":"This API configures lifecycle rules for a bucket to periodically delete objects in the bucket or transition objects between storage classes.An object will be automaticall", + "doc_type":"sdk-java-devg", + "kw":"Setting Lifecycle Rules,Lifecycle Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Setting Lifecycle Rules", + "githuburl":"" + }, + { + "uri":"obs_21_1103.html", + "node_id":"obs_21_1103.xml", + "product_code":"obs", + "code":"90", + "des":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API returns the lifecycle rules of a bucket.To obtain ", + "doc_type":"sdk-java-devg", + "kw":"Obtaining Lifecycle Rules,Lifecycle Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining Lifecycle Rules", + "githuburl":"" + }, + { + "uri":"obs_21_1104.html", + "node_id":"obs_21_1104.xml", + "product_code":"obs", + "code":"91", + "des":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API deletes the lifecycle configuration of a bucket.To", + "doc_type":"sdk-java-devg", + "kw":"Deleting Lifecycle Rules,Lifecycle Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting Lifecycle Rules", + "githuburl":"" + }, + { + "uri":"obs_21_1400.html", + "node_id":"obs_21_1400.xml", + "product_code":"obs", + "code":"92", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Cross-Origin Resource Sharing", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Cross-Origin Resource Sharing", + "githuburl":"" + }, + { + "uri":"obs_21_1401.html", + "node_id":"obs_21_1401.xml", + "product_code":"obs", + "code":"93", + "des":"Cross-origin access refers to access between different domains. Restricting cross-origin access is a browser policy for security purposes, that is, the same-origin policy", + "doc_type":"sdk-java-devg", + "kw":"Overview,Cross-Origin Resource Sharing,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1402.html", + "node_id":"obs_21_1402.xml", + "product_code":"obs", + "code":"94", + "des":"Cross-origin resource sharing (CORS) is a mechanism defined by the World Wide Web Consortium (W3C) that allows a web application program in one domain to access resources", + "doc_type":"sdk-java-devg", + "kw":"Configuring a CORS Rule,Cross-Origin Resource Sharing,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring a CORS Rule", + "githuburl":"" + }, + { + "uri":"obs_21_1403.html", + "node_id":"obs_21_1403.xml", + "product_code":"obs", + "code":"95", + "des":"CORS is a browser-standard mechanism defined by the W3C. It allows a web client in one origin to interact with resources in another. For general web page requests, websit", + "doc_type":"sdk-java-devg", + "kw":"Obtaining a CORS Rule,Cross-Origin Resource Sharing,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining a CORS Rule", + "githuburl":"" + }, + { + "uri":"obs_21_1404.html", + "node_id":"obs_21_1404.xml", + "product_code":"obs", + "code":"96", + "des":"CORS is a browser-standard mechanism defined by the W3C. It allows a web client in one origin to interact with resources in another. For general web page requests, websit", + "doc_type":"sdk-java-devg", + "kw":"Deleting a CORS Rule,Cross-Origin Resource Sharing,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting a CORS Rule", + "githuburl":"" + }, + { + "uri":"obs_21_1500.html", + "node_id":"obs_21_1500.xml", + "product_code":"obs", + "code":"97", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Logging", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Logging", + "githuburl":"" + }, + { + "uri":"obs_21_1501.html", + "node_id":"obs_21_1501.xml", + "product_code":"obs", + "code":"98", + "des":"OBS allows you to configure access logging for buckets. After the configuration, access to buckets will be recorded in logs. These logs will be saved in specific buckets ", + "doc_type":"sdk-java-devg", + "kw":"Overview,Logging,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1502.html", + "node_id":"obs_21_1502.xml", + "product_code":"obs", + "code":"99", + "des":"This API enables logging for a bucket (source) and configures another bucket (target) to store the log files. When a bucket is created, logging is not enabled by default.", + "doc_type":"sdk-java-devg", + "kw":"Configuring Logging for a Bucket,Logging,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Logging for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_1503.html", + "node_id":"obs_21_1503.xml", + "product_code":"obs", + "code":"100", + "des":"This API returns the logging configuration of a bucket.To obtain the logging configuration of a bucket, you must be the bucket owner or have the required permission (obs:", + "doc_type":"sdk-java-devg", + "kw":"Obtaining the Logging Configuration of a Bucket,Logging,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining the Logging Configuration of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_1600.html", + "node_id":"obs_21_1600.xml", + "product_code":"obs", + "code":"101", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Static Website Hosting", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Static Website Hosting", + "githuburl":"" + }, + { + "uri":"obs_21_1601.html", + "node_id":"obs_21_1601.xml", + "product_code":"obs", + "code":"102", + "des":"To host your static website on OBS, you can upload static website files to your bucket as objects, configure the public read permission for the objects, and then configur", + "doc_type":"sdk-java-devg", + "kw":"Overview,Static Website Hosting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1602.html", + "node_id":"obs_21_1602.xml", + "product_code":"obs", + "code":"103", + "des":"To host your static website on OBS, you can upload static website files to your bucket as objects, configure the public read permission for the objects, and then configur", + "doc_type":"sdk-java-devg", + "kw":"Hosting Website Files in a Bucket,Static Website Hosting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Hosting Website Files in a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_1603.html", + "node_id":"obs_21_1603.xml", + "product_code":"obs", + "code":"104", + "des":"You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using", + "doc_type":"sdk-java-devg", + "kw":"Configuring Static Website Hosting,Static Website Hosting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Static Website Hosting", + "githuburl":"" + }, + { + "uri":"obs_21_1604.html", + "node_id":"obs_21_1604.xml", + "product_code":"obs", + "code":"105", + "des":"You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using", + "doc_type":"sdk-java-devg", + "kw":"Obtaining Static Website Hosting Configurations,Static Website Hosting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining Static Website Hosting Configurations", + "githuburl":"" + }, + { + "uri":"obs_21_1605.html", + "node_id":"obs_21_1605.xml", + "product_code":"obs", + "code":"106", + "des":"You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using", + "doc_type":"sdk-java-devg", + "kw":"Deleting Static Website Hosting Configurations,Static Website Hosting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting Static Website Hosting Configurations", + "githuburl":"" + }, + { + "uri":"obs_21_1700.html", + "node_id":"obs_21_1700.xml", + "product_code":"obs", + "code":"107", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Bucket Tag Management", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Bucket Tag Management", + "githuburl":"" + }, + { + "uri":"obs_21_1701.html", + "node_id":"obs_21_1701.xml", + "product_code":"obs", + "code":"108", + "des":"Tags are used to identify and classify OBS buckets.If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can us", + "doc_type":"sdk-java-devg", + "kw":"Overview,Bucket Tag Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1702.html", + "node_id":"obs_21_1702.xml", + "product_code":"obs", + "code":"109", + "des":"If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analy", + "doc_type":"sdk-java-devg", + "kw":"Configuring Tags for a Bucket,Bucket Tag Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Configuring Tags for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_21_1703.html", + "node_id":"obs_21_1703.xml", + "product_code":"obs", + "code":"110", + "des":"If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analy", + "doc_type":"sdk-java-devg", + "kw":"Obtaining Bucket Tags,Bucket Tag Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Obtaining Bucket Tags", + "githuburl":"" + }, + { + "uri":"obs_21_1704.html", + "node_id":"obs_21_1704.xml", + "product_code":"obs", + "code":"111", + "des":"If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analy", + "doc_type":"sdk-java-devg", + "kw":"Deleting Bucket Tags,Bucket Tag Management,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Deleting Bucket Tags", + "githuburl":"" + }, + { + "uri":"obs_21_1900.html", + "node_id":"obs_21_1900.xml", + "product_code":"obs", + "code":"112", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Server-Side Encryption", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Server-Side Encryption", + "githuburl":"" + }, + { + "uri":"obs_21_1901.html", + "node_id":"obs_21_1901.xml", + "product_code":"obs", + "code":"113", + "des":"OBS provides server-side encryption for objects, so that they will be encrypted or decrypted when you upload them to or download them from a bucket.The encryption and dec", + "doc_type":"sdk-java-devg", + "kw":"Overview,Server-Side Encryption,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_1902.html", + "node_id":"obs_21_1902.xml", + "product_code":"obs", + "code":"114", + "des":"The following table lists APIs related to server-side encryption:", + "doc_type":"sdk-java-devg", + "kw":"Server-Side Encryption APIs,Server-Side Encryption,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Server-Side Encryption APIs", + "githuburl":"" + }, + { + "uri":"obs_21_1903.html", + "node_id":"obs_21_1903.xml", + "product_code":"obs", + "code":"115", + "des":"The following code shows an example of encrypting an object with SSE-C before uploading it:The following code shows an example of downloading an object encrypted with SSE", + "doc_type":"sdk-java-devg", + "kw":"Code Examples for Server-Side Encryption,Server-Side Encryption,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Code Examples for Server-Side Encryption", + "githuburl":"" + }, + { + "uri":"obs_21_2301.html", + "node_id":"obs_21_2301.xml", + "product_code":"obs", + "code":"116", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Client-Side Encryption", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Client-Side Encryption", + "githuburl":"" + }, + { + "uri":"obs_21_2302.html", + "node_id":"obs_21_2302.xml", + "product_code":"obs", + "code":"117", + "des":"Client-side encryption is a process where data is encrypted using the selected encryption method and information on your local PC before it is transmitted to an OBS serve", + "doc_type":"sdk-java-devg", + "kw":"Overview,Client-Side Encryption,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_21_2303.html", + "node_id":"obs_21_2303.xml", + "product_code":"obs", + "code":"118", + "des":"OBS SDK for Java provides two cipher suites for you to choose from.CtrRSACipherGenerator is inherited from CTRCipherGenerator but only requires you to provide an RSA publ", + "doc_type":"sdk-java-devg", + "kw":"Client-Side Encryption APIs,Client-Side Encryption,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Client-Side Encryption APIs", + "githuburl":"" + }, + { + "uri":"obs_21_0300.html", + "node_id":"obs_21_0300.xml", + "product_code":"obs", + "code":"119", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Fault Locating", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Fault Locating", + "githuburl":"" + }, + { + "uri":"obs_21_0301.html", + "node_id":"obs_21_0301.xml", + "product_code":"obs", + "code":"120", + "des":"If problems occur when using the OBS Java SDK, you can perform the following steps to analyze and locate the problems.You can click here to view the details about ObsExce", + "doc_type":"sdk-java-devg", + "kw":"Methods,Fault Locating,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Methods", + "githuburl":"" + }, + { + "uri":"obs_21_0303.html", + "node_id":"obs_21_0303.xml", + "product_code":"obs", + "code":"121", + "des":"Dependency missing and dependency conflict are commonly encountered in Java development or during SDK integration. If error message \"ClassNotFoundException\" or \"NoClassDe", + "doc_type":"sdk-java-devg", + "kw":"Resolving Dependency Missing or Conflicts,Fault Locating,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Resolving Dependency Missing or Conflicts", + "githuburl":"" + }, + { + "uri":"obs_21_0302.html", + "node_id":"obs_21_0302.xml", + "product_code":"obs", + "code":"122", + "des":"Possible causes are as follows:The SK input into ObsClient initialization is incorrect. Solution: Make sure that the SK is correct.This problem is caused by a bug in the ", + "doc_type":"sdk-java-devg", + "kw":"Other Notable Issues,Fault Locating,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Other Notable Issues", + "githuburl":"" + }, + { + "uri":"obs_21_2000.html", + "node_id":"obs_21_2000.xml", + "product_code":"obs", + "code":"123", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Troubleshooting", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Troubleshooting", + "githuburl":"" + }, + { + "uri":"obs_21_2001.html", + "node_id":"obs_21_2001.xml", + "product_code":"obs", + "code":"124", + "des":"The OBS server complies with the HTTP standard. After an API is called, the OBS server returns a standard HTTP status code. The following tables list the categories of HT", + "doc_type":"sdk-java-devg", + "kw":"HTTP Status Codes,Troubleshooting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"HTTP Status Codes", + "githuburl":"" + }, + { + "uri":"obs_21_2002.html", + "node_id":"obs_21_2002.xml", + "product_code":"obs", + "code":"125", + "des":"If the OBS server encounters an error when processing a request, a response containing the error code and error description is returned. The following table lists details", + "doc_type":"sdk-java-devg", + "kw":"OBS Server-side Error Codes,Troubleshooting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"OBS Server-side Error Codes", + "githuburl":"" + }, + { + "uri":"obs_21_2005.html", + "node_id":"obs_21_2005.xml", + "product_code":"obs", + "code":"126", + "des":"SDK custom exceptions (ObsException), thrown by ObsClient, are inherited from class java.lang.RuntimeException. Exceptions are usually OBS server errors, including OBS er", + "doc_type":"sdk-java-devg", + "kw":"SDK Exceptions,Troubleshooting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"SDK Exceptions", + "githuburl":"" + }, + { + "uri":"obs_21_2003.html", + "node_id":"obs_21_2003.xml", + "product_code":"obs", + "code":"127", + "des":"After you successfully call an API in an instance of ObsClient, an instance of the HeaderResponse class (or of its sub-class) will be returned.It contains information abo", + "doc_type":"sdk-java-devg", + "kw":"SDK Common Response Headers,Troubleshooting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"SDK Common Response Headers", + "githuburl":"" + }, + { + "uri":"obs_21_2004.html", + "node_id":"obs_21_2004.xml", + "product_code":"obs", + "code":"128", + "des":"Save the log4j2.xml file obtained from the OBS Java SDK package to the classpath root directory.Call Log4j2Configurator.setLogConfig to specify the save path of log4j2.xm", + "doc_type":"sdk-java-devg", + "kw":"Log Analysis,Troubleshooting,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Log Analysis", + "githuburl":"" + }, + { + "uri":"obs_21_2100.html", + "node_id":"obs_21_2100.xml", + "product_code":"obs", + "code":"129", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"FAQs", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"FAQs", + "githuburl":"" + }, + { + "uri":"obs_21_2107.html", + "node_id":"obs_21_2107.xml", + "product_code":"obs", + "code":"130", + "des":"To do this, perform the following steps:", + "doc_type":"sdk-java-devg", + "kw":"How Can I Set an Object to Be Accessible to Anonymous Users?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Can I Set an Object to Be Accessible to Anonymous Users?", + "githuburl":"" + }, + { + "uri":"obs_21_2109.html", + "node_id":"obs_21_2109.xml", + "product_code":"obs", + "code":"131", + "des":"SDK uses the maxErrorRetry parameter configured in Creating and Configuring an OBS Client to retry. The default value for retry times is 3. 0 to 5 is recommended.If the n", + "doc_type":"sdk-java-devg", + "kw":"What Is the Retry Mechanism of SDK?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"What Is the Retry Mechanism of SDK?", + "githuburl":"" + }, + { + "uri":"obs_21_2110.html", + "node_id":"obs_21_2110.xml", + "product_code":"obs", + "code":"132", + "des":"After a bucket is configured to work in static website hosting mode, you can use the following method to combine the static website access address of the bucket.https://b", + "doc_type":"sdk-java-devg", + "kw":"How Do I Obtain the Static Website Access Address of a Bucket?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Obtain the Static Website Access Address of a Bucket?", + "githuburl":"" + }, + { + "uri":"obs_21_2111.html", + "node_id":"obs_21_2111.xml", + "product_code":"obs", + "code":"133", + "des":"If the uploaded object is set to be read by anonymous users, anonymous users can download the object through the object URL directly. Methods to obtain the object URL are", + "doc_type":"sdk-java-devg", + "kw":"How Do I Obtain an Object URL?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Obtain an Object URL?", + "githuburl":"" + }, + { + "uri":"obs_21_2112.html", + "node_id":"obs_21_2112.xml", + "product_code":"obs", + "code":"134", + "des":"If a file exceeds 100 MB, you are advised to upload the file using multipart upload.Multipart upload refers to splitting an object into multiple parts and uploading them ", + "doc_type":"sdk-java-devg", + "kw":"How to Improve the Speed of Uploading Large Files over the Public Network?,FAQs,Developer Guide (Jav", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How to Improve the Speed of Uploading Large Files over the Public Network?", + "githuburl":"" + }, + { + "uri":"obs_21_2114.html", + "node_id":"obs_21_2114.xml", + "product_code":"obs", + "code":"135", + "des":"In a multipart upload, you can specify a part of the file to be uploaded by performing the following steps:For details, see Multipart Upload.", + "doc_type":"sdk-java-devg", + "kw":"How Can I Perform a Multipart Upload?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Can I Perform a Multipart Upload?", + "githuburl":"" + }, + { + "uri":"obs_21_2115.html", + "node_id":"obs_21_2115.xml", + "product_code":"obs", + "code":"136", + "des":"In a multipart download, you can specify the range of data to be downloaded. The procedure is as follows:For details, see Downloading an Object - Range-Based.", + "doc_type":"sdk-java-devg", + "kw":"How Can I Perform a Download in Multipart Mode?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Can I Perform a Download in Multipart Mode?", + "githuburl":"" + }, + { + "uri":"obs_21_2117.html", + "node_id":"obs_21_2117.xml", + "product_code":"obs", + "code":"137", + "des":"After the upload is complete, you can call ObsClient.getObjectMetadata to obtain the size and last modification time of the newly uploaded object and compare them with th", + "doc_type":"sdk-java-devg", + "kw":"How Do I Confirm that an Upload is Successful If I Upload an Object to Overwrite an Existing Object ", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Confirm that an Upload is Successful If I Upload an Object to Overwrite an Existing Object with the Same Name in a Bucket?", + "githuburl":"" + }, + { + "uri":"obs_21_2118.html", + "node_id":"obs_21_2118.xml", + "product_code":"obs", + "code":"138", + "des":"If the object is encrypted with SSE-KMS, the server automatically decrypts the object when you use the URL of the object to download it.If the object is encrypted with SS", + "doc_type":"sdk-java-devg", + "kw":"How Do I Download an Encrypted Object Using a URL?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Download an Encrypted Object Using a URL?", + "githuburl":"" + }, + { + "uri":"obs_21_2119.html", + "node_id":"obs_21_2119.xml", + "product_code":"obs", + "code":"139", + "des":"Sample code of generating an SSE-C encryption key and its MD5 value:", + "doc_type":"sdk-java-devg", + "kw":"How Do I Generate an SSE-C Encryption Key?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Generate an SSE-C Encryption Key?", + "githuburl":"" + }, + { + "uri":"obs_21_2121.html", + "node_id":"obs_21_2121.xml", + "product_code":"obs", + "code":"140", + "des":"No.Currently, the SDK does not provide such APIs. You need to encapsulate the service codes for uploading, downloading, or copying objects in a batch by yourself. The pro", + "doc_type":"sdk-java-devg", + "kw":"Does the SDK Support Uploading, Downloading, or Copying Objects in a Batch?,FAQs,Developer Guide (Ja", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Does the SDK Support Uploading, Downloading, or Copying Objects in a Batch?", + "githuburl":"" + }, + { + "uri":"obs_21_2124.html", + "node_id":"obs_21_2124.xml", + "product_code":"obs", + "code":"141", + "des":"Multipurpose Internet Mail Extensions (MIME) type is a standard way of describing a data type. The MIME type is passed in the Content-Type header.If you do not specify Co", + "doc_type":"sdk-java-devg", + "kw":"What Is Content-Type (MIME)?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"What Is Content-Type (MIME)?", + "githuburl":"" + }, + { + "uri":"obs_23_1712.html", + "node_id":"obs_23_1712.xml", + "product_code":"obs", + "code":"142", + "des":"When calling APIs, you may need to specify the account ID (DomainID) and user ID (UserID) in some requests. You need to obtain them from the console in advance. To obtain", + "doc_type":"sdk-java-devg", + "kw":"How Do I Get My Account ID and User ID?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Get My Account ID and User ID?", + "githuburl":"" + }, + { + "uri":"obs_23_1713.html", + "node_id":"obs_23_1713.xml", + "product_code":"obs", + "code":"143", + "des":"This example limits the upload rate by specifying thex-obs-traffic-limitheader. The SDK transparently transmits the header for the server to verify.", + "doc_type":"sdk-java-devg", + "kw":"How Do I Limit the Rate During Object Upload?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Limit the Rate During Object Upload?", + "githuburl":"" + }, + { + "uri":"obs_23_1714.html", + "node_id":"obs_23_1714.xml", + "product_code":"obs", + "code":"144", + "des":"This example limits the download rate by specifying thex-obs-traffic-limitheader. The SDK transparently transmits the header for the server to verify.", + "doc_type":"sdk-java-devg", + "kw":"How Do I Limit the Rate During Object Download?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"How Do I Limit the Rate During Object Download?", + "githuburl":"" + }, + { + "uri":"obs_23_1715.html", + "node_id":"obs_23_1715.xml", + "product_code":"", + "code":"145", + "des":"This example uploads localfile to examplebucket as objectkey and sets the referer header to https://example.com*.", + "doc_type":"", + "kw":"How Do I Configure the referer Header?,FAQs,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + + } + ], + "title":"How Do I Configure the referer Header?", + "githuburl":"" + }, + { + "uri":"obs_21_2202.html", + "node_id":"obs_21_2202.xml", + "product_code":"obs", + "code":"146", + "des":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "doc_type":"sdk-java-devg", + "kw":"Change History,Developer Guide (Java SDK)", + "search_title":"", + "metedata":[ + { + "opensource":"false;true", + "prodname":"obs", + "documenttype":"sdk-java-devg" + } + ], + "title":"Change History", + "githuburl":"" + } +] \ No newline at end of file diff --git a/docs/obs_3rd_party/java_sdk/CLASS.TXT.json b/docs/obs_3rd_party/java_sdk/CLASS.TXT.json new file mode 100644 index 000000000..92d3bcf6b --- /dev/null +++ b/docs/obs_3rd_party/java_sdk/CLASS.TXT.json @@ -0,0 +1,1316 @@ +[ + { + "desc":"This section describes version compatibility and important notes about Object Storage Service (OBS) SDK for Java.Recommended JDK versions: JDK 8 or laterThird-party depen", + "product_code":"obs", + "title":"Before You Start", + "uri":"obs_21_0101.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"1" + }, + { + "desc":"Table 1 lists the bucket-related APIs.Table 2lists object-related APIs.Table 3 lists the APIs related to temporarily authorized access.Table 4 lists the APIs related to v", + "product_code":"obs", + "title":"API Overview", + "uri":"obs_21_0002.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"2" + }, + { + "desc":"Before using OBS SDK for Java to access OBS, you need to prepare the service and development environments. To prepare the service environment, you will need an account an", + "product_code":"obs", + "title":"Preparations", + "uri":"obs_21_0102.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"3" + }, + { + "desc":"Latest version of OBS Java SDK: DownloadYou can download the source code of SDK for Java and compile the source code to create a JAR package. Before using this method, en", + "product_code":"obs", + "title":"SDK Download and Installation", + "uri":"obs_21_0001.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"4" + }, + { + "desc":"This section introduces how to use OBS SDK for Java to perform some basic actions, such as creating a bucket, and uploading, downloading, listing, and deleting objects.En", + "product_code":"obs", + "title":"Getting Started", + "uri":"obs_21_0100.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"5" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Initialization", + "uri":"obs_21_0200.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"6" + }, + { + "desc":"After the SDK is installed, you need to create and configure an OBS client and configure the logging for the SDK to complete the initialization.", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_0201.html", + "doc_type":"sdk-java-devg", + "p_code":"6", + "code":"7" + }, + { + "desc":"This section describes how to create and configure an OBS client. If you already have a client, skip this section and obtain the API details by referring to API Overview.", + "product_code":"obs", + "title":"Creating and Configuring an OBS Client", + "uri":"obs_21_0202.html", + "doc_type":"sdk-java-devg", + "p_code":"6", + "code":"8" + }, + { + "desc":"OBS SDK for Java offers logging based on the open-source Apache Log4j 2 library. By default, the SDK stores WARN log files to the directory specified by the JDK system va", + "product_code":"obs", + "title":"Configuring SDK Logging", + "uri":"obs_21_0204.html", + "doc_type":"sdk-java-devg", + "p_code":"6", + "code":"9" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Bucket Management", + "uri":"obs_21_0400.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"10" + }, + { + "desc":"This API creates an OBS bucket. Buckets are containers for storing objects (files uploaded to OBS) in OBS.When creating a bucket, you can also configure parameters such a", + "product_code":"obs", + "title":"Creating a Bucket", + "uri":"obs_21_0401.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"11" + }, + { + "desc":"OBS buckets are containers for storing objects you upload to OBS. This API returns a list of all buckets that meet the specified conditions in all regions of the current ", + "product_code":"obs", + "title":"Obtaining a Bucket List", + "uri":"obs_21_0402.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"12" + }, + { + "desc":"This API deletes an empty bucket. You can delete buckets you no longer use to free up space. The name of a deleted bucket can be reused for another bucket at least 30 min", + "product_code":"obs", + "title":"Deleting a Bucket", + "uri":"obs_21_0403.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"13" + }, + { + "desc":"This API checks whether a bucket exists. If an HTTP status code 200 is returned, the bucket exists. If 404 is returned, the bucket does not exist.To check whether a bucke", + "product_code":"obs", + "title":"Checking Whether a Bucket Exists", + "uri":"obs_21_0404.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"14" + }, + { + "desc":"This API returns information about a bucket, including the storage class, region, CORS rules, and redundancy policy.To obtain bucket metadata, you must be the bucket owne", + "product_code":"obs", + "title":"Obtaining Bucket Metadata", + "uri":"obs_21_0405.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"15" + }, + { + "desc":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "product_code":"obs", + "title":"Setting a Bucket ACL", + "uri":"obs_21_0406.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"16" + }, + { + "desc":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "product_code":"obs", + "title":"Obtaining a Bucket ACL", + "uri":"obs_21_0412.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"17" + }, + { + "desc":"OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control ca", + "product_code":"obs", + "title":"Configuring a Bucket Policy", + "uri":"obs_21_0407.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"18" + }, + { + "desc":"OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control ca", + "product_code":"obs", + "title":"Obtaining the Policy of a Bucket", + "uri":"obs_21_0413.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"19" + }, + { + "desc":"OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control ca", + "product_code":"obs", + "title":"Deleting a Bucket Policy", + "uri":"obs_21_0414.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"20" + }, + { + "desc":"This API returns the region where a bucket is located.To obtain the region of a bucket, you must be the bucket owner or have the required permission (obs:bucket:GetBucket", + "product_code":"obs", + "title":"Obtaining the Region of a Bucket", + "uri":"obs_21_0408.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"21" + }, + { + "desc":"This API returns the storage information of a bucket, including the number of objects and the space occupied by the objects in the bucket.OBS measures bucket storage stat", + "product_code":"obs", + "title":"Obtaining Storage Information of a Bucket", + "uri":"obs_21_0409.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"22" + }, + { + "desc":"A quota limits the maximum capacity allowed in a bucket. By default, there is no limit on the storage capacity of the entire OBS system or a single bucket, and any number", + "product_code":"obs", + "title":"Configuring a Storage Quota", + "uri":"obs_21_0410.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"23" + }, + { + "desc":"This API returns the storage quota (upper limit of the storage capacity) of a bucket. If the quota is 0, there is no upper limit on the bucket capacity.A bucket quota mus", + "product_code":"obs", + "title":"Obtaining a Bucket Storage Quota", + "uri":"obs_21_0415.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"24" + }, + { + "desc":"This API configures a storage class for a bucket. If you do not specify a storage class when uploading or copying an object, or initiating a multipart upload, the object ", + "product_code":"obs", + "title":"Configuring a Storage Class for a Bucket", + "uri":"obs_21_0411.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"25" + }, + { + "desc":"This API returns the storage class of a bucket.To obtain a bucket's storage class, you must be the bucket owner or have the required permission (obs:bucket:GetBucketStora", + "product_code":"obs", + "title":"Obtaining the Storage Class of a Bucket", + "uri":"obs_21_0416.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"26" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Bucket Inventory", + "uri":"obs_21_0421.html", + "doc_type":"sdk-java-devg", + "p_code":"10", + "code":"27" + }, + { + "desc":"This API configures an inventory rule for the bucket. With this API, object information in a bucket (source) is regularly listed and saved as CSV files. These files are t", + "product_code":"obs", + "title":"Configuring an Inventory Rule", + "uri":"obs_21_0417.html", + "doc_type":"sdk-java-devg", + "p_code":"27", + "code":"28" + }, + { + "desc":"This API returns an inventory rule (identified by configurationId) for the bucket.To obtain a bucket inventory rule, you must be the bucket owner or have the required per", + "product_code":"obs", + "title":"Obtaining an Inventory Rule", + "uri":"obs_21_0418.html", + "doc_type":"sdk-java-devg", + "p_code":"27", + "code":"29" + }, + { + "desc":"This API returns a list of all inventory rules for the bucket.To list inventory rules for a bucket, you must be the bucket owner or have the required permission (obs:buck", + "product_code":"obs", + "title":"Listing Inventory Rules", + "uri":"obs_21_0419.html", + "doc_type":"sdk-java-devg", + "p_code":"27", + "code":"30" + }, + { + "desc":"This API deletes an inventory rule (identified by configurationId) from the bucket.To delete a bucket inventory rule, you must be the bucket owner or have the required pe", + "product_code":"obs", + "title":"Deleting an Inventory Rule", + "uri":"obs_21_0420.html", + "doc_type":"sdk-java-devg", + "p_code":"27", + "code":"31" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Object Upload", + "uri":"obs_21_0600.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"32" + }, + { + "desc":"In OBS, objects are basic data units that users can perform operations on. OBS Java SDK provides abundant APIs for object upload in the following methods:StreamingFile-ba", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_0601.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"33" + }, + { + "desc":"This API uploads a local fileto OBS over the Internet. These files can be texts, images, videos, or any other type of files.You can upload texts, images, videos, or any o", + "product_code":"obs", + "title":"Uploading an Object - Streaming", + "uri":"obs_21_0602.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"34" + }, + { + "desc":"This API uploads local filesto OBS over the Internet. The file to be uploaded can be of any type.To upload an object, you must be the bucket owner or have the required pe", + "product_code":"obs", + "title":"Uploading an Object - File-Based", + "uri":"obs_21_0603.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"35" + }, + { + "desc":"This API returns the upload progress of a specified object.You can call PutObjectRequest.setProgressListener to obtain the upload progress.To obtain the upload progress, ", + "product_code":"obs", + "title":"Obtaining the Upload Progress", + "uri":"obs_21_0604.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"36" + }, + { + "desc":"This API creates a folder in an existing bucket to manage data in OBS.OBS does not involve folders like in a file system. All elements in buckets are objects. To create a", + "product_code":"obs", + "title":"Creating a Folder", + "uri":"obs_21_0605.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"37" + }, + { + "desc":"This API configures metadata for an object when uploading it. Object metadata include the object length, MIME type, MD5 value (for verification), storage class, and custo", + "product_code":"obs", + "title":"Configuring Object Metadata", + "uri":"obs_21_0606.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"38" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Multipart Upload", + "uri":"obs_21_0607.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"39" + }, + { + "desc":"You can upload large files using multipart upload. Multipart upload is applicable to many scenarios, including:Files to be uploaded are larger than 100 MB.The network con", + "product_code":"obs", + "title":"Multipart Upload Overview", + "uri":"obs_21_0614.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"40" + }, + { + "desc":"This API initiates a multipart upload and returns a globally unique upload ID. You can use this upload ID in your subsequent requests including abortMultipartUpload, list", + "product_code":"obs", + "title":"Initiating a Multipart Upload", + "uri":"obs_21_0615.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"41" + }, + { + "desc":"After a multipart upload is initiated, this API uploads a part to a specified bucket. In the upload request, the multipart upload ID must be included. Except for the part", + "product_code":"obs", + "title":"Uploading a Part", + "uri":"obs_21_0616.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"42" + }, + { + "desc":"This API assembles the uploaded parts to complete the multipart upload. Before performing this operation, you cannot download the uploaded data. When assembling parts, yo", + "product_code":"obs", + "title":"Assembling Parts", + "uri":"obs_21_0617.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"43" + }, + { + "desc":"Multipart upload is mainly used for large file upload or when the network connection is poor.You can use UploadPartRequest.setOffset and UploadPartRequest.setPartSize to ", + "product_code":"obs", + "title":"Code Example of a Multipart Upload", + "uri":"obs_21_0618.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"44" + }, + { + "desc":"This API aborts a multipart upload using the multipart upload ID.After a multipart upload is aborted, the upload ID cannot be used to upload any part. The storage occupie", + "product_code":"obs", + "title":"Aborting a Multipart Upload", + "uri":"obs_21_0619.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"45" + }, + { + "desc":"This API lists the uploaded parts in a specified bucket. This request must contain the multipart upload ID.You can list the uploaded parts of a specified multipart upload", + "product_code":"obs", + "title":"Listing Uploaded Parts", + "uri":"obs_21_0620.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"46" + }, + { + "desc":"This API lists ongoing multipart uploads.Ongoing multipart uploads are the multipart uploads that have been initiated but have not been completed or aborted. A maximum of", + "product_code":"obs", + "title":"Listing Multipart Uploads", + "uri":"obs_21_0621.html", + "doc_type":"sdk-java-devg", + "p_code":"39", + "code":"47" + }, + { + "desc":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes. The object expiration time set using this API takes preced", + "product_code":"obs", + "title":"Configuring Lifecycle Rules", + "uri":"obs_21_0608.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"48" + }, + { + "desc":"This API uploads a file or folder to an existing OBS bucket. These files can be texts, images, videos, or any other type of files.The appendObject operation adds data to ", + "product_code":"obs", + "title":"Uploading an Object - Append", + "uri":"obs_21_0609.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"49" + }, + { + "desc":"The resumable upload is an encapsulated and enhanced version of the multipart upload used for dealing with possible upload failures of large files when the network connec", + "product_code":"obs", + "title":"Uploading an Object - Resumable", + "uri":"obs_21_0611.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"50" + }, + { + "desc":"This API uploads an object up to 5 GB to a specified bucket in HTML form.You can call ObsClient.createPostSignature to generate request parameters for a browser-based upl", + "product_code":"obs", + "title":"Uploading an Object - Browser-Based", + "uri":"obs_21_0612.html", + "doc_type":"sdk-java-devg", + "p_code":"32", + "code":"51" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Object Download", + "uri":"obs_21_0700.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"52" + }, + { + "desc":"OBS Java SDK provides abundant APIs for object download in the following methods:Streaming DownloadPartial DownloadResumable download", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_0701.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"53" + }, + { + "desc":"When you call ObsClient.getObject, an instance of ObsObject will be returned. This instance contains the contents of the object such as its name, attributes, input stream", + "product_code":"obs", + "title":"Downloading an Object - Streaming", + "uri":"obs_21_0702.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"54" + }, + { + "desc":"This API downloads partial data of an object by specifying a range. If the specified range is from 0 to 1,000, data from byte 0 to byte 1,000, 1,001 bytes in total, are r", + "product_code":"obs", + "title":"Downloading an Object - Range-Based", + "uri":"obs_21_0703.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"55" + }, + { + "desc":"This API returns the download progress of a specified object.You can call GetObjectRequest.setProgressInterval to obtain the download progress.To obtain the download prog", + "product_code":"obs", + "title":"Obtaining the Download Progress", + "uri":"obs_21_0704.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"56" + }, + { + "desc":"This API returns the objects that meet one or more conditions. If there are no objects that meet the specified conditions, an error is returned.To download an object, you", + "product_code":"obs", + "title":"Downloading an Object - Conditional", + "uri":"obs_21_0705.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"57" + }, + { + "desc":"This API rewrites the following HTTP/HTTPS response headers when downloading an object: Content-Type, Content-Language, Expires, Cache-Control, Content-Disposition, and C", + "product_code":"obs", + "title":"Rewriting Response Headers", + "uri":"obs_21_0706.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"58" + }, + { + "desc":"Object metadata is a set of key-value pairs that describe the object and is used for object management.This API returns the user-defined object metadata after the object ", + "product_code":"obs", + "title":"Obtaining User-defined Metadata", + "uri":"obs_21_0707.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"59" + }, + { + "desc":"Cold objects must first be restored before you can download them. Cold objects can be restored in either of the following ways.To restore a Cold object, you must be the b", + "product_code":"obs", + "title":"Restoring a Cold Object", + "uri":"obs_21_0708.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"60" + }, + { + "desc":"Downloading large files often fails due to an unstable network or program breakdown. It is a waste of resources to download files again. Moreover, the restarted download ", + "product_code":"obs", + "title":"Downloading an Object - Resumable", + "uri":"obs_21_0709.html", + "doc_type":"sdk-java-devg", + "p_code":"52", + "code":"61" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Object Management", + "uri":"obs_21_0800.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"62" + }, + { + "desc":"Object metadata is a set of name-value pairs that describe the object and is used for object management.Currently, only the system-defined metadata is supported.There are", + "product_code":"obs", + "title":"Configuring Object Metadata", + "uri":"obs_21_0806.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"63" + }, + { + "desc":"Object metadata is a set of name-value pairs that describe the object and is used for object management.Users with the READ permission on objects can send HEAD requests t", + "product_code":"obs", + "title":"Obtaining Object Metadata", + "uri":"obs_21_0801.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"64" + }, + { + "desc":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "product_code":"obs", + "title":"Configuring an Object ACL", + "uri":"obs_21_0802.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"65" + }, + { + "desc":"Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over r", + "product_code":"obs", + "title":"Obtaining an Object ACL", + "uri":"obs_21_0808.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"66" + }, + { + "desc":"This API lists some or all of the objects in a bucket. You can use parameters such as the prefix, number of returned objects, and start position to list objects that meet", + "product_code":"obs", + "title":"Listing Objects", + "uri":"obs_21_0803.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"67" + }, + { + "desc":"This API deletes objects from a specific bucket.To delete an object, you must be the bucket owner or have the required permission (obs:object:DeleteObject in IAM or Delet", + "product_code":"obs", + "title":"Deleting an Object", + "uri":"obs_21_0804.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"68" + }, + { + "desc":"This API deletes objects in batches from a specific bucket. Deleted objects cannot be recovered.In a batch delete operation, OBS concurrently deletes the specified object", + "product_code":"obs", + "title":"Batch Deleting Objects", + "uri":"obs_21_0809.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"69" + }, + { + "desc":"This API copies an object stored in OBS to another path, with a copy created during the process. You can create a copy of an object up to 5 GB in a single operation.To co", + "product_code":"obs", + "title":"Copying an Object", + "uri":"obs_21_0805.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"70" + }, + { + "desc":"This API allows you to upload a part by copying an object or part of this object.You can call ObsClient.copyPart to copy parts.To copy an object, you must be the bucket o", + "product_code":"obs", + "title":"Copying an Object - Multipart", + "uri":"obs_21_0810.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"71" + }, + { + "desc":"This API checks whether an object exists. If the returned HTTP status code is 200, the object exists. If the returned HTTP status code is 404, the object or bucket does n", + "product_code":"obs", + "title":"Checking Whether an Object Exists", + "uri":"obs_21_0807.html", + "doc_type":"sdk-java-devg", + "p_code":"62", + "code":"72" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Temporarily Authorized Access", + "uri":"obs_21_0900.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"73" + }, + { + "desc":"ObsClient allows you to create a URL with Query parameters that carry authentication information by specifying the AK and SK, HTTP method, and request parameters. You can", + "product_code":"obs", + "title":"Accessing OBS Using a Signed URL", + "uri":"obs_21_0901.html", + "doc_type":"sdk-java-devg", + "p_code":"73", + "code":"74" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Versioning", + "uri":"obs_21_1000.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"75" + }, + { + "desc":"You can use versioning to store multiple versions of an object in a bucket.When versioning is enabled for a bucket, OBS keeps multiple versions of an object in the bucket", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1001.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"76" + }, + { + "desc":"You can enable versioning to automatically maintain previous versions of an object. When versioning is enabled, you can access earlier versions of an object to recover yo", + "product_code":"obs", + "title":"Configuring Versioning for a Bucket", + "uri":"obs_21_1002.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"77" + }, + { + "desc":"You can enable versioning to automatically maintain previous versions of an object. When versioning is enabled, you can access earlier versions of an object to recover yo", + "product_code":"obs", + "title":"Obtaining the Versioning Status of a Bucket", + "uri":"obs_21_1003.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"78" + }, + { + "desc":"You can call ObsClient.getObject to obtain an object version by specifying the version ID (versionId).To download an object, you must be the bucket owner or have the requ", + "product_code":"obs", + "title":"Obtaining an Object Version", + "uri":"obs_21_1004.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"79" + }, + { + "desc":"This API copies an object version in a specified bucket.You can call ObsClient.copyObject to copy an object version by specifying the version ID (versionId).To copy an ob", + "product_code":"obs", + "title":"Copying an Object Version", + "uri":"obs_21_1005.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"80" + }, + { + "desc":"This API downloads a Cold object. To download such an object, you must restore it first. For the options for the restore speed, see Table 3.You can call ObsClient.restore", + "product_code":"obs", + "title":"Restoring a Specific Cold Object Version", + "uri":"obs_21_1006.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"81" + }, + { + "desc":"This API lists some or all of the object versions in a bucket. When listing the object versions, you can specify the criteria such as the prefix, number, and start positi", + "product_code":"obs", + "title":"Listing Object Versions", + "uri":"obs_21_1007.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"82" + }, + { + "desc":"OBS allows the control of access permissions for objects. By default, only object creators have the read and write permissions on the object. You can set access control p", + "product_code":"obs", + "title":"Setting an ACL for an Object Version", + "uri":"obs_21_1008.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"83" + }, + { + "desc":"OBS allows the control of access permissions for objects. By default, only object creators have the read and write permissions on the object. You can call an ACL API to m", + "product_code":"obs", + "title":"Obtaining the ACL of an Object Version", + "uri":"obs_21_1010.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"84" + }, + { + "desc":"This API deletes an object from a specific bucket.You can call ObsClient.deleteObject to pass a version ID (versionId) to delete an object version.To delete an object, yo", + "product_code":"obs", + "title":"Deleting an Object Version", + "uri":"obs_21_1009.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"85" + }, + { + "desc":"This API deletes objects in batches from a specific bucket. Deleted objects cannot be recovered.In a batch delete operation, OBS concurrently deletes the specified object", + "product_code":"obs", + "title":"Batch Deleting Object Versions", + "uri":"obs_21_1011.html", + "doc_type":"sdk-java-devg", + "p_code":"75", + "code":"86" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Lifecycle Management", + "uri":"obs_21_1100.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"87" + }, + { + "desc":"OBS allows you to set lifecycle rules for buckets to automatically transition the storage class of an object or delete expired objects, to effectively use storage feature", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1101.html", + "doc_type":"sdk-java-devg", + "p_code":"87", + "code":"88" + }, + { + "desc":"This API configures lifecycle rules for a bucket to periodically delete objects in the bucket or transition objects between storage classes.An object will be automaticall", + "product_code":"obs", + "title":"Setting Lifecycle Rules", + "uri":"obs_21_1102.html", + "doc_type":"sdk-java-devg", + "p_code":"87", + "code":"89" + }, + { + "desc":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API returns the lifecycle rules of a bucket.To obtain ", + "product_code":"obs", + "title":"Obtaining Lifecycle Rules", + "uri":"obs_21_1103.html", + "doc_type":"sdk-java-devg", + "p_code":"87", + "code":"90" + }, + { + "desc":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API deletes the lifecycle configuration of a bucket.To", + "product_code":"obs", + "title":"Deleting Lifecycle Rules", + "uri":"obs_21_1104.html", + "doc_type":"sdk-java-devg", + "p_code":"87", + "code":"91" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Cross-Origin Resource Sharing", + "uri":"obs_21_1400.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"92" + }, + { + "desc":"Cross-origin access refers to access between different domains. Restricting cross-origin access is a browser policy for security purposes, that is, the same-origin policy", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1401.html", + "doc_type":"sdk-java-devg", + "p_code":"92", + "code":"93" + }, + { + "desc":"Cross-origin resource sharing (CORS) is a mechanism defined by the World Wide Web Consortium (W3C) that allows a web application program in one domain to access resources", + "product_code":"obs", + "title":"Configuring a CORS Rule", + "uri":"obs_21_1402.html", + "doc_type":"sdk-java-devg", + "p_code":"92", + "code":"94" + }, + { + "desc":"CORS is a browser-standard mechanism defined by the W3C. It allows a web client in one origin to interact with resources in another. For general web page requests, websit", + "product_code":"obs", + "title":"Obtaining a CORS Rule", + "uri":"obs_21_1403.html", + "doc_type":"sdk-java-devg", + "p_code":"92", + "code":"95" + }, + { + "desc":"CORS is a browser-standard mechanism defined by the W3C. It allows a web client in one origin to interact with resources in another. For general web page requests, websit", + "product_code":"obs", + "title":"Deleting a CORS Rule", + "uri":"obs_21_1404.html", + "doc_type":"sdk-java-devg", + "p_code":"92", + "code":"96" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Logging", + "uri":"obs_21_1500.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"97" + }, + { + "desc":"OBS allows you to configure access logging for buckets. After the configuration, access to buckets will be recorded in logs. These logs will be saved in specific buckets ", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1501.html", + "doc_type":"sdk-java-devg", + "p_code":"97", + "code":"98" + }, + { + "desc":"This API enables logging for a bucket (source) and configures another bucket (target) to store the log files. When a bucket is created, logging is not enabled by default.", + "product_code":"obs", + "title":"Configuring Logging for a Bucket", + "uri":"obs_21_1502.html", + "doc_type":"sdk-java-devg", + "p_code":"97", + "code":"99" + }, + { + "desc":"This API returns the logging configuration of a bucket.To obtain the logging configuration of a bucket, you must be the bucket owner or have the required permission (obs:", + "product_code":"obs", + "title":"Obtaining the Logging Configuration of a Bucket", + "uri":"obs_21_1503.html", + "doc_type":"sdk-java-devg", + "p_code":"97", + "code":"100" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Static Website Hosting", + "uri":"obs_21_1600.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"101" + }, + { + "desc":"To host your static website on OBS, you can upload static website files to your bucket as objects, configure the public read permission for the objects, and then configur", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1601.html", + "doc_type":"sdk-java-devg", + "p_code":"101", + "code":"102" + }, + { + "desc":"To host your static website on OBS, you can upload static website files to your bucket as objects, configure the public read permission for the objects, and then configur", + "product_code":"obs", + "title":"Hosting Website Files in a Bucket", + "uri":"obs_21_1602.html", + "doc_type":"sdk-java-devg", + "p_code":"101", + "code":"103" + }, + { + "desc":"You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using", + "product_code":"obs", + "title":"Configuring Static Website Hosting", + "uri":"obs_21_1603.html", + "doc_type":"sdk-java-devg", + "p_code":"101", + "code":"104" + }, + { + "desc":"You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using", + "product_code":"obs", + "title":"Obtaining Static Website Hosting Configurations", + "uri":"obs_21_1604.html", + "doc_type":"sdk-java-devg", + "p_code":"101", + "code":"105" + }, + { + "desc":"You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using", + "product_code":"obs", + "title":"Deleting Static Website Hosting Configurations", + "uri":"obs_21_1605.html", + "doc_type":"sdk-java-devg", + "p_code":"101", + "code":"106" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Bucket Tag Management", + "uri":"obs_21_1700.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"107" + }, + { + "desc":"Tags are used to identify and classify OBS buckets.If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can us", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1701.html", + "doc_type":"sdk-java-devg", + "p_code":"107", + "code":"108" + }, + { + "desc":"If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analy", + "product_code":"obs", + "title":"Configuring Tags for a Bucket", + "uri":"obs_21_1702.html", + "doc_type":"sdk-java-devg", + "p_code":"107", + "code":"109" + }, + { + "desc":"If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analy", + "product_code":"obs", + "title":"Obtaining Bucket Tags", + "uri":"obs_21_1703.html", + "doc_type":"sdk-java-devg", + "p_code":"107", + "code":"110" + }, + { + "desc":"If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analy", + "product_code":"obs", + "title":"Deleting Bucket Tags", + "uri":"obs_21_1704.html", + "doc_type":"sdk-java-devg", + "p_code":"107", + "code":"111" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Server-Side Encryption", + "uri":"obs_21_1900.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"112" + }, + { + "desc":"OBS provides server-side encryption for objects, so that they will be encrypted or decrypted when you upload them to or download them from a bucket.The encryption and dec", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_1901.html", + "doc_type":"sdk-java-devg", + "p_code":"112", + "code":"113" + }, + { + "desc":"The following table lists APIs related to server-side encryption:", + "product_code":"obs", + "title":"Server-Side Encryption APIs", + "uri":"obs_21_1902.html", + "doc_type":"sdk-java-devg", + "p_code":"112", + "code":"114" + }, + { + "desc":"The following code shows an example of encrypting an object with SSE-C before uploading it:The following code shows an example of downloading an object encrypted with SSE", + "product_code":"obs", + "title":"Code Examples for Server-Side Encryption", + "uri":"obs_21_1903.html", + "doc_type":"sdk-java-devg", + "p_code":"112", + "code":"115" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Client-Side Encryption", + "uri":"obs_21_2301.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"116" + }, + { + "desc":"Client-side encryption is a process where data is encrypted using the selected encryption method and information on your local PC before it is transmitted to an OBS serve", + "product_code":"obs", + "title":"Overview", + "uri":"obs_21_2302.html", + "doc_type":"sdk-java-devg", + "p_code":"116", + "code":"117" + }, + { + "desc":"OBS SDK for Java provides two cipher suites for you to choose from.CtrRSACipherGenerator is inherited from CTRCipherGenerator but only requires you to provide an RSA publ", + "product_code":"obs", + "title":"Client-Side Encryption APIs", + "uri":"obs_21_2303.html", + "doc_type":"sdk-java-devg", + "p_code":"116", + "code":"118" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Fault Locating", + "uri":"obs_21_0300.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"119" + }, + { + "desc":"If problems occur when using the OBS Java SDK, you can perform the following steps to analyze and locate the problems.You can click here to view the details about ObsExce", + "product_code":"obs", + "title":"Methods", + "uri":"obs_21_0301.html", + "doc_type":"sdk-java-devg", + "p_code":"119", + "code":"120" + }, + { + "desc":"Dependency missing and dependency conflict are commonly encountered in Java development or during SDK integration. If error message \"ClassNotFoundException\" or \"NoClassDe", + "product_code":"obs", + "title":"Resolving Dependency Missing or Conflicts", + "uri":"obs_21_0303.html", + "doc_type":"sdk-java-devg", + "p_code":"119", + "code":"121" + }, + { + "desc":"Possible causes are as follows:The SK input into ObsClient initialization is incorrect. Solution: Make sure that the SK is correct.This problem is caused by a bug in the ", + "product_code":"obs", + "title":"Other Notable Issues", + "uri":"obs_21_0302.html", + "doc_type":"sdk-java-devg", + "p_code":"119", + "code":"122" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Troubleshooting", + "uri":"obs_21_2000.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"123" + }, + { + "desc":"The OBS server complies with the HTTP standard. After an API is called, the OBS server returns a standard HTTP status code. The following tables list the categories of HT", + "product_code":"obs", + "title":"HTTP Status Codes", + "uri":"obs_21_2001.html", + "doc_type":"sdk-java-devg", + "p_code":"123", + "code":"124" + }, + { + "desc":"If the OBS server encounters an error when processing a request, a response containing the error code and error description is returned. The following table lists details", + "product_code":"obs", + "title":"OBS Server-side Error Codes", + "uri":"obs_21_2002.html", + "doc_type":"sdk-java-devg", + "p_code":"123", + "code":"125" + }, + { + "desc":"SDK custom exceptions (ObsException), thrown by ObsClient, are inherited from class java.lang.RuntimeException. Exceptions are usually OBS server errors, including OBS er", + "product_code":"obs", + "title":"SDK Exceptions", + "uri":"obs_21_2005.html", + "doc_type":"sdk-java-devg", + "p_code":"123", + "code":"126" + }, + { + "desc":"After you successfully call an API in an instance of ObsClient, an instance of the HeaderResponse class (or of its sub-class) will be returned.It contains information abo", + "product_code":"obs", + "title":"SDK Common Response Headers", + "uri":"obs_21_2003.html", + "doc_type":"sdk-java-devg", + "p_code":"123", + "code":"127" + }, + { + "desc":"Save the log4j2.xml file obtained from the OBS Java SDK package to the classpath root directory.Call Log4j2Configurator.setLogConfig to specify the save path of log4j2.xm", + "product_code":"obs", + "title":"Log Analysis", + "uri":"obs_21_2004.html", + "doc_type":"sdk-java-devg", + "p_code":"123", + "code":"128" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"FAQs", + "uri":"obs_21_2100.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"129" + }, + { + "desc":"To do this, perform the following steps:", + "product_code":"obs", + "title":"How Can I Set an Object to Be Accessible to Anonymous Users?", + "uri":"obs_21_2107.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"130" + }, + { + "desc":"SDK uses the maxErrorRetry parameter configured in Creating and Configuring an OBS Client to retry. The default value for retry times is 3. 0 to 5 is recommended.If the n", + "product_code":"obs", + "title":"What Is the Retry Mechanism of SDK?", + "uri":"obs_21_2109.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"131" + }, + { + "desc":"After a bucket is configured to work in static website hosting mode, you can use the following method to combine the static website access address of the bucket.https://b", + "product_code":"obs", + "title":"How Do I Obtain the Static Website Access Address of a Bucket?", + "uri":"obs_21_2110.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"132" + }, + { + "desc":"If the uploaded object is set to be read by anonymous users, anonymous users can download the object through the object URL directly. Methods to obtain the object URL are", + "product_code":"obs", + "title":"How Do I Obtain an Object URL?", + "uri":"obs_21_2111.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"133" + }, + { + "desc":"If a file exceeds 100 MB, you are advised to upload the file using multipart upload.Multipart upload refers to splitting an object into multiple parts and uploading them ", + "product_code":"obs", + "title":"How to Improve the Speed of Uploading Large Files over the Public Network?", + "uri":"obs_21_2112.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"134" + }, + { + "desc":"In a multipart upload, you can specify a part of the file to be uploaded by performing the following steps:For details, see Multipart Upload.", + "product_code":"obs", + "title":"How Can I Perform a Multipart Upload?", + "uri":"obs_21_2114.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"135" + }, + { + "desc":"In a multipart download, you can specify the range of data to be downloaded. The procedure is as follows:For details, see Downloading an Object - Range-Based.", + "product_code":"obs", + "title":"How Can I Perform a Download in Multipart Mode?", + "uri":"obs_21_2115.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"136" + }, + { + "desc":"After the upload is complete, you can call ObsClient.getObjectMetadata to obtain the size and last modification time of the newly uploaded object and compare them with th", + "product_code":"obs", + "title":"How Do I Confirm that an Upload is Successful If I Upload an Object to Overwrite an Existing Object with the Same Name in a Bucket?", + "uri":"obs_21_2117.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"137" + }, + { + "desc":"If the object is encrypted with SSE-KMS, the server automatically decrypts the object when you use the URL of the object to download it.If the object is encrypted with SS", + "product_code":"obs", + "title":"How Do I Download an Encrypted Object Using a URL?", + "uri":"obs_21_2118.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"138" + }, + { + "desc":"Sample code of generating an SSE-C encryption key and its MD5 value:", + "product_code":"obs", + "title":"How Do I Generate an SSE-C Encryption Key?", + "uri":"obs_21_2119.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"139" + }, + { + "desc":"No.Currently, the SDK does not provide such APIs. You need to encapsulate the service codes for uploading, downloading, or copying objects in a batch by yourself. The pro", + "product_code":"obs", + "title":"Does the SDK Support Uploading, Downloading, or Copying Objects in a Batch?", + "uri":"obs_21_2121.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"140" + }, + { + "desc":"Multipurpose Internet Mail Extensions (MIME) type is a standard way of describing a data type. The MIME type is passed in the Content-Type header.If you do not specify Co", + "product_code":"obs", + "title":"What Is Content-Type (MIME)?", + "uri":"obs_21_2124.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"141" + }, + { + "desc":"When calling APIs, you may need to specify the account ID (DomainID) and user ID (UserID) in some requests. You need to obtain them from the console in advance. To obtain", + "product_code":"obs", + "title":"How Do I Get My Account ID and User ID?", + "uri":"obs_23_1712.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"142" + }, + { + "desc":"This example limits the upload rate by specifying thex-obs-traffic-limitheader. The SDK transparently transmits the header for the server to verify.", + "product_code":"obs", + "title":"How Do I Limit the Rate During Object Upload?", + "uri":"obs_23_1713.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"143" + }, + { + "desc":"This example limits the download rate by specifying thex-obs-traffic-limitheader. The SDK transparently transmits the header for the server to verify.", + "product_code":"obs", + "title":"How Do I Limit the Rate During Object Download?", + "uri":"obs_23_1714.html", + "doc_type":"sdk-java-devg", + "p_code":"129", + "code":"144" + }, + { + "desc":"This example uploads localfile to examplebucket as objectkey and sets the referer header to https://example.com*.", + "product_code":"", + "title":"How Do I Configure the referer Header?", + "uri":"obs_23_1715.html", + "doc_type":"", + "p_code":"129", + "code":"145" + }, + { + "desc":"HUAWEI CLOUD Help Center presents technical documents to help you quickly get started with HUAWEI CLOUD services. The technical documents include Service Overview, Price Details, Purchase Guide, User Guide, API Reference, Best Practices, FAQs, and Videos.", + "product_code":"obs", + "title":"Change History", + "uri":"obs_21_2202.html", + "doc_type":"sdk-java-devg", + "p_code":"", + "code":"146" + } +] \ No newline at end of file diff --git a/docs/obs_3rd_party/java_sdk/PARAMETERS.txt b/docs/obs_3rd_party/java_sdk/PARAMETERS.txt new file mode 100644 index 000000000..6da8d5f07 --- /dev/null +++ b/docs/obs_3rd_party/java_sdk/PARAMETERS.txt @@ -0,0 +1,3 @@ +version="" +language="en-us" +type="" \ No newline at end of file diff --git a/docs/obs_3rd_party/java_sdk/en-us_image_0000001580082852.png b/docs/obs_3rd_party/java_sdk/en-us_image_0000001580082852.png new file mode 100644 index 000000000..2b0302fb6 Binary files /dev/null and b/docs/obs_3rd_party/java_sdk/en-us_image_0000001580082852.png differ diff --git a/docs/obs_3rd_party/java_sdk/en-us_image_0000001809221937.png b/docs/obs_3rd_party/java_sdk/en-us_image_0000001809221937.png new file mode 100644 index 000000000..1a8efd0c9 Binary files /dev/null and b/docs/obs_3rd_party/java_sdk/en-us_image_0000001809221937.png differ diff --git a/docs/obs_3rd_party/java_sdk/obs_21_0001.html b/docs/obs_3rd_party/java_sdk/obs_21_0001.html new file mode 100644 index 000000000..942475794 --- /dev/null +++ b/docs/obs_3rd_party/java_sdk/obs_21_0001.html @@ -0,0 +1,15 @@ + + +
You can download the source code of SDK for Java and compile the source code to create a JAR package. Before using this method, ensure that the Java and Maven environments are correctly configured and can be used properly.
+mvn clean package -Dmaven.test.skip=true -f pom-java.xml+
mvn clean package "-Dmaven.test.skip=true" -f pom-java.xml+
Table 1 lists the bucket-related APIs.
+API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.createBucket(CreateBucketRequest request) + |
+Creates a bucket and configures the storage class, region, and ACL for the bucket. + |
+
| + | +obsClient.listBuckets(ListBucketsRequest request) + |
+Lists all buckets that meet the specified conditions under the current account and returns them in alphabetical order. + |
+
| + | +obsClient.deleteBucket(String bucketName) + |
+Deletes an empty bucket (the name of a deleted bucket can be reused at least 30 minutes after the deletion). + |
+
| + | +obsClient.headBucket(String bucketName) + |
+Checks whether a bucket exists (HTTP status code 200 indicates the bucket exists, while 404 indicates it does not). + |
+
| + | +obsClient.getBucketMetadata(BucketMetadataInfoRequest request) + |
+Returns information about a bucket, including the storage class, region, CORS rules, and redundancy policy. + |
+
| + | +obsClient.setBucketAcl(String bucketName,AccessControlList acl) + |
+Sets an ACL for a bucket. + |
+
| + | +obsClient.getBucketAcl(String bucketName) + |
+Returns the ACL of a bucket. + |
+
| + | +obsClient.setBucketPolicy(String bucketName, String policy) + |
+Sets a bucket policy. + |
+
| + | +obsClient.getBucketPolicy(String bucketName) + |
+Returns a bucket policy. + |
+
| + | +obsClient.deleteBucketPolicy(String bucketName) + |
+Deletes a bucket policy (204 No Content is returned if the policy is deleted successfully or actually does not exist). + |
+
| + | +obsClient.getBucketLocation(String bucketName) + |
+Returns the region where the bucket is created. + |
+
| + | +obsClient.getBucketStorageInfo(String bucketName) + |
+Returns the storage information about a bucket, including the storage usage and the object count in the bucket. + |
+
| + | +obsClient.setBucketQuota(String bucketName, BucketQuota bucketQuota) + |
+Sets a limit on the capacity of a bucket. + |
+
| + | +obsClient.getBucketQuota(String bucketName) + |
+Returns the quota of a bucket (0 indicates there is no upper limit to the capacity of the bucket). + |
+
| + | +obsClient.setBucketStoragePolicy(String bucketName, BucketStoragePolicyConfiguration bucketStorage) + |
+Specifies the storage class for a bucket (after the bucket storage class is configured, if you do not specifically configure the storage class for objects in that bucket, those objects will inherit the storage class of the bucket by default). + |
+
| + | +obsClient.getBucketStoragePolicy(String bucketName) + |
+Returns the storage class of a bucket. + |
+
| + | +obsClient.setInventoryConfiguration(SetInventoryConfigurationRequest request) + |
+Configures an inventory rule for a bucket (you can specify the object attributes to include in inventories, such as the object version, size, storage class, tag, encryption status, and last modification). + |
+
| + | +obsClient.getInventoryConfiguration(GetInventoryConfigurationRequest request) + |
+Returns a bucket inventory rule specified by the rule ID. + |
+
| + | +obsClient.listInventoryConfiguration(ListInventoryConfigurationRequest request) + |
+Returns all inventory rules of a bucket in a single response. + |
+
| + | +obsClient.deleteInventoryConfiguration(DeleteInventoryConfigurationRequest request) + |
+Deletes a bucket inventory rule specified by the rule ID. + |
+
Table 2lists object-related APIs.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.putObject(PutObjectRequest request) + |
+Uploads local files of any type that are smaller than 5 GB to a bucket in streaming mode. + |
+
| + | +obsClient.putObject(PutObjectRequest request) + |
+Uploads local files of any type to a bucket over the Internet. + |
+
| + | +PutObjectRequest.setProgressListener(ProgressListener progressListener) + |
+Returns the progress of uploading an object. + |
+
| + | +obsClient.putObject(PutObjectRequest request) + |
+Creates a folder in a bucket to categorize the data. + |
+
| + | +obsClient.setObjectMetadata(SetObjectMetadataRequest request) + |
+Sets object attributes (such as the size, MIME type, MD5 value, storage class, or user-defined metadata) when uploading an object in streaming, file-based, or multipart mode, or when copying an object. + |
+
| + | +obsClient.initiateMultipartUpload(InitiateMultipartUploadRequest request) + |
+Initiates a multipart upload and returns a globally unique upload ID. + |
+
| + | +obsClient.uploadPart(UploadPartRequest request) + |
+Uploads parts to the bucket based on the upload ID returned by the preceding API. + |
+
| + | +obsClient.completeMultipartUpload(CompleteMultipartUploadRequest request) + |
+Completes a multipart upload based on the multipart upload ID and information about the uploaded parts (including PartNumber and ETag). + |
+
| + | +obsClient.abortMultipartUpload(AbortMultipartUploadRequest request) + |
+Aborts a multipart upload specified by the upload ID in a bucket. + |
+
| + | +obsClient.listParts(ListPartsRequest request) + |
+Returns the uploaded parts in a bucket based on the specified multipart upload ID. + |
+
| + | +obsClient.listMultipartUploads(ListMultipartUploadsRequest request) + |
+Lists ongoing multipart uploads. + |
+
| + | +obsClient.putObject(PutObjectRequest request) + |
+Configures a lifecycle rule for objects to periodically delete objects in the bucket or transition object storage classes (the object expiration time set using this API takes precedence over that set in a bucket lifecycle rule). + |
+
| + | +obsClient.appendObject(AppendObjectRequest request) + |
+Appends content to an existing object. + |
+
| + | +obsClient.uploadFile(UploadFileRequest request) + |
+Provides the resumable function based on the API for multipart uploads to better respond to network disconnections or program crashes. + |
+
| + | +obsClient.createPostSignature(PostSignatureRequest request) + |
+Uploads an object up to 5 GB in size to a bucket in the HTML form. + |
+
| + | +obsClient.getObject(GetObjectRequest request) + |
+Downloads an object from OBS to a local directory or memory (the returned results contain the object name, attributes, input stream, and bucket information). + |
+
| + | +obsClient.getObject(GetObjectRequest request) + |
+Downloads the partial data of an object. + |
+
| + | +GetObjectRequest.setProgressListener(ProgressListener progressListener) + |
+Returns the progress of downloading an object. + |
+
| + | +obsClient.getObject(GetObjectRequest request) + |
+Returns the objects that meet one or more specified conditions. + |
+
| + | +obsClient.getObject(GetObjectRequest request) + |
+Rewrites the following HTTP/HTTPS response headers when downloading an object: Content-Type, Content-Language, Expires, Cache-Control, Content-Disposition, and Content-Encoding. + |
+
| + | +obsClient.getObject(GetObjectRequest request) + |
+Returns the user-defined object metadata after the object is successfully downloaded. + |
+
| + | +obsClient.restoreObject(RestoreObjectRequest request) + |
+Restores and downloads a Cold object. + |
+
| + | +obsClient.downloadFile(DownloadFileRequest request) + |
+Adds the resumable function to the partial download API. + |
+
| + | +obsClient.setObjectMetadata(SetObjectMetadataRequest request) + |
+Configures the object metadata. + |
+
| + | +obsClient.getObjectMetadata(GetObjectMetadataRequest request) + |
+Returns the object metadata. + |
+
| + | +obsClient.setObjectAcl(SetObjectAclRequest request) + |
+Sets an ACL for an object when uploading the object or modifies the ACL of an existing object by calling an ACL API. + |
+
| + | +obsClient.getObjectAcl(GetObjectAclRequest request) + |
+Obtains the ACL of an object in a specified bucket. + |
+
| + | +obsClient.listObjects(ListObjectsRequest request) + |
+Lists some or all objects in a bucket based on the specified prefix, object count, and start position and returns the objects in alphabetical order. + |
+
| + | +obsClient.deleteObject(DeleteObjectRequest request) + |
+Deletes an object from a bucket. + |
+
| + | +obsClient.deleteObjects(DeleteObjectsRequest deleteRequest) + |
+Deletes objects from a bucket in a batch. +(Deleted objects cannot be restored.) + |
+
| + | +obsClient.copyObject(CopyObjectRequest request) + |
+Creates a copy up to 5 GB for an object. + |
+
| + | +obsClient.copyPart(CopyPartRequest request) + |
+Copies parts to a specified bucket based on the multipart upload ID returned in initiating a multipart upload. + |
+
| + | +doesObjectExist(final GetObjectMetadataRequest request) + |
+Checks whether an object exists (HTTP status code 200 indicates the object exists, while 404 indicates the object or bucket does not exist). + |
+
Table 3 lists the APIs related to temporarily authorized access.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.createTemporarySignature(TemporarySignatureRequest request) + |
+Creates a signed URL and specifies the expiration time for the URL to grant visitors temporary access. +(To allow other users to perform a temporary operation such as upload, you need to generate a URL for the corresponding operation and offer that to users.) + |
+
Table 4 lists the APIs related to versioning.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.setBucketVersioning(final SetBucketVersioningRequest request) + |
+Configures versioning for objects in a bucket. + |
+
| + | +obsClient.getBucketVersioning(final BaseBucketRequest request) + |
+Returns the versioning status of a bucket. + |
+
| + | +obsClient.getObject(GetObjectRequest request) + |
+Returns a specified object version. + |
+
| + | +obsClient.copyObject(CopyObjectRequest request) + |
+Creates a copy up to 5 GB for a versioned object. + |
+
| + | +obsClient.restoreObject(RestoreObjectRequest request) + |
+Restores a Cold object version. +(To download a Cold object version, you need to restore it first.) + |
+
| + | +obsClient.listVersions(ListVersionsRequest request) + |
+Lists some or all object versions in a bucket based on the specified prefix, version count, and start position and returns the versions in alphabetical order. + |
+
| + | +obsClient.setObjectAcl(SetObjectAclRequest request) + |
+Sets an ACL for an object version. + |
+
| + | +obsClient.getObjectAcl(GetObjectAclRequest request) + |
+Returns the ACL of an object version. + |
+
| + | +obsClient.deleteObject(DeleteObjectRequest request) + |
+Deletes the ACL of an object version. + |
+
| + | +obsClient.deleteObjects(DeleteObjectsRequest deleteRequest) + |
+Deletes object versions from a bucket in a batch. +(Deleted object versions cannot be restored.) + |
+
Table 5 lists the APIs related to lifecycle rules.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.setBucketLifecycle(final SetBucketLifecycleRequest request) + |
+Sets a lifecycle rule for a bucket to periodically delete objects in the bucket or transition object storage classes. + |
+
| + | +obsClient.getBucketLifecycle(final BaseBucketRequest request) + |
+Returns a lifecycle rule of a bucket. + |
+
| + | +obsClient.deleteBucketLifecycle(final BaseBucketRequest request) + |
+Deletes a lifecycle rule of a bucket. + |
+
Table 6 lists the APIs related to CORS rules.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsclient.setBucketCors(final SetBucketCorsRequest request) + |
+Sets a CORS rule for a bucket (the existing rules will be overwritten by the new ones). + |
+
| + | +obsclient.getBucketCors(final BaseBucketRequest request) + |
+Returns a CORS rule of a bucket. + |
+
| + | +obsclient.deleteBucketCors(final BaseBucketRequest request) + |
+Deletes a CORS rule of a bucket. + |
+
Table 7 lists the logging APIs.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.setBucketLogging(final SetBucketLoggingRequest request) + |
+Enables logging for a source bucket, specifies a target bucket for storing log files, and configures the name prefixes and access permissions for log files. + |
+
| + | +obsClient.getBucketLogging(final BaseBucketRequest request) + |
+Returns the logging configuration of a bucket. + |
+
Table 8 lists the APIs related to static website hosting.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +
|
+Uploads the files of a static website to a specified bucket in OBS, configures the public read permission for the files, and enables static website hosting for the bucket. + |
+
| + | +obsClient.setBucketWebsite(final SetBucketWebsiteRequest request) + |
+Configures website hosting for a bucket. + |
+
| + | +obsClient.getBucketWebsite(final BaseBucketRequest request) + |
+Returns the website configuration of a bucket. + |
+
| + | +obsClient.deleteBucketWebsite(final BaseBucketRequest request) + |
+Deletes the website configuration of a bucket. + |
+
Table 9 lists the APIs related to tagging.
+ +API + |
+Method + |
+Function + |
+
|---|---|---|
| + | +obsClient.setBucketTagging(final SetBucketTaggingRequest request) + |
+Tags a bucket to facilitate CDR filtering and cost analysis. + |
+
| + | +obsClient.getBucketTagging(final BaseBucketRequest request) + |
+Returns the tags of a bucket. + |
+
| + | +obsClient.deleteBucketTagging(final BaseBucketRequest request) + |
+Deletes the tags of a bucket. + |
+
This section introduces how to use OBS SDK for Java to perform some basic actions, such as creating a bucket, and uploading, downloading, listing, and deleting objects.
+Ensure you have made the following preparations before using the SDK:
+The example below shows how to create a bucket named examplebucket, and configure access, storage class, region, and redundancy type for the bucket. For more details about how to create a bucket, see Creating a Bucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.AvailableZoneEnum; +import com.obs.services.model.CreateBucketRequest; +import com.obs.services.model.ObsBucket; +import com.obs.services.model.StorageClassEnum; + +public class CreateBucket001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + CreateBucketRequest request = new CreateBucketRequest(); + // Example bucket name + String exampleBucket = "examplebucket"; + // Example bucket location + request.setBucketName(exampleBucket); + // Set the bucket ACL to Private (the default value). + request.setAcl(AccessControlList.REST_CANNED_PRIVATE); + // Set the bucket storage class to Standard. + request.setBucketStorageClass(StorageClassEnum.STANDARD); + request.setLocation(exampleLocation); + // Create a bucket. + ObsBucket bucket = obsClient.createBucket(request); + // The bucket is created. + System.out.println("CreateBucket successfully"); + System.out.println("RequestId:"+bucket.getRequestId()); + + + } catch (ObsException e) { + System.out.println("CreateBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("CreateBucket failed"); + // Print other error information. + e.printStackTrace(); + + } + } +} + |
The example below shows how to upload two local files localfile and localfile2 to the bucket examplebucket, and specify the names of the objects created as objectkey and objectkey2 respectively. For more details about uploading an object, see Object Upload.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload files. + // localfile indicates the path of the local file to be uploaded, in which the file name must be specified. + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectkey"); + request.setFile(new File("localfile")); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The example below shows how to download the object objectname from the bucket examplebucket. For more details about downloading an object, see Object Download.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsObject; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +public class GetObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Download the object using streaming. + ObsObject obsObject = obsClient.getObject("examplebucket", "objectname"); + // Read the object content. + System.out.println("Object content:"); + InputStream input = obsObject.getObjectContent(); + byte[] b = new byte[1024]; + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + int len; + while ((len = input.read(b)) != -1) { + bos.write(b, 0, len); + } + System.out.println("getObjectContent successfully"); + System.out.println(new String(bos.toByteArray())); + bos.close(); + input.close(); + } catch (ObsException e) { + System.out.println("getObjectContent failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectContent failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The example below shows how to list objects in the bucket examplebucket. For more details about object listing, see Listing Objects.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Listing objects. + ObjectListing result = obsClient.listObjects("examplebucket"); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The example below shows how to delete the object objectname from the bucket examplebucket. For more details about deleting an object, see Deleting an Object.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete the object. + obsClient.deleteObject("examplebucket", "objectname"); + System.out.println("deleteObject successfully"); + } catch (ObsException e) { + System.out.println("deleteObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The example below shows how to use an ObsClient instance.
+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 | // Make sure there is only one ObsClient instance in the whole project. +// ObsClient is thread-safe and can be used in concurrency scenarios. +ObsClient obsClient = null; +try +{ + String endPoint = "https://your-endpoint"; + // Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // Create an ObsClient instance. + obsClient = new ObsClient(ak, sk, endPoint); + // Call an API to perform an operation, for example, uploading an object. +HeaderResponse response = obsClient.putObject("bucketname", "objectname", new File("localfile")); // localfile indicates the path of the local file to be uploaded. Use the file path in your case. + System.out.println(response); +} +catch (ObsException e) +{ + System.out.println("HTTP Code: " + e.getResponseCode()); + System.out.println("Error Code:" + e.getErrorCode()); + System.out.println("Error Message: " + e.getErrorMessage()); + + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + Map<String, String> headers = e.getResponseHeaders();// Check all map entries and print all headers with errors reported. + if(headers != null){ + for (Map.Entry<String, String> header : headers.entrySet()) { + System.out.println(header.getKey()+":"+header.getValue()); + } + } + e.printStackTrace(); +}finally{ + // Close the ObsClient instance. If the instance is used globally, skip this step. + // After the ObsClient instance is closed by calling ObsClient.close, it cannot be used again. + if(obsClient != null){ + try + { + // obsClient.close(); + } + catch (IOException e) + { + } + } +} + |
This section describes version compatibility and important notes about Object Storage Service (OBS) SDK for Java.
+Before using OBS SDK for Java to access OBS, you need to prepare the service and development environments. To prepare the service environment, you will need an account and access keys. Both of them are necessary for interaction between OBS SDK and OBS. To ensure successful SDK installation and SDK-based code development and running, you should also set up a local development environment, for example, installing dependencies and development tools.
+Access keys consist of two parts: an access key ID (AK) and a secret access key (SK). OBS uses access keys to sign requests to make sure that only authorized accounts can access specified OBS resources. Programmatic access must be enabled for an IAM user before the IAM user can get access keys. Access keys are explained as follows:
+Access keys are classified into permanent access keys (AK/SK) and temporary access keys (AK/SK and security token). Each user can create at most two permanent access keys. Temporary access keys must be used within a given validity period. Once expired, they must be requested again. For security purposes, you are advised to use temporary access keys to access OBS. If you want to use permanent access keys, periodically update them. The following describes how to obtain two types of access keys.
+
Temporary access keys are issued by the system and are only valid for 15 minutes to 24 hours. Once expired, they must be requested again. They follow the principle of least privilege. When a temporary AK/SK pair is used for authentication, a security token must be used at the same time.
+After the SDK is installed, you need to create and configure an OBS client and configure the logging for the SDK to complete the initialization.
+ +Task + |
+Sub-task + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +Creating an OBS client + |
+Yes + |
+OBS clients offer a series of APIs for you to use OBS SDK for Java to interact with OBS. Before sending a request to OBS, you need to create and initialize an OBS client (an ObsClient instance). + |
+
Configuring access credentials + |
+Yes + |
+For security purposes, you need to configure access credentials for the client so that the server can verify the validity of requests. + |
+|
Configuring the endpoint and other parameters + |
+Yes for the endpoint; No for other parameters + |
+
|
+|
| + | +Configuring a log level + |
+No + |
+OBS SDK for Java offers logging based on the open-source library of Apache Log4j 2. The Log4j 2 framework classifies log files into different levels based on their priorities. You can specify a log level to customize the log storage scope. +By default, OBS SDK for Java saves log files of the WARN and higher levels to local directories. + |
+
Configuring a storage path for log files + |
+No + |
+Configure a local path to store logs. + |
+
This section describes how to create and configure an OBS client. If you already have a client, skip this section and obtain the API details by referring to API Overview.
+Ensure you have completed the following preparations:
+You can select a client class, a method of obtaining access credentials, and other parameters by referring to Figure 1.
+ +Category + |
+Option + |
+Description + |
+Sample Code + |
+
|---|---|---|---|
Client + |
+Client that does not transparently transmit access credentials + |
+If you want to configure access credentials only once and use them for all API calls, use ObsClient. + |
++ | +
Client that transparently transmits access credentials + |
+If you need to configure access credentials for each API call, use SecretFlexibleObsClient, which is inherited from ObsClient. + |
++ | +|
Access credentials + |
+Passing access credentials as parameters + |
+Create an ObsClient instance and pass access credentials as parameters. + |
++ | +
Obtaining access credentials from environment variables + |
+Create an ObsClient instance and use EnvironmentVariableObsCredentialsProvider to obtain access credentials from environment variables. + + |
++ | +|
Obtaining access credentials from an agency in ECS scenarios + |
+Create an ObsClient instance and use EcsObsCredentialsProvider to automatically obtain temporary access credentials from the ECS. The access credentials are periodically updated automatically. + NOTICE:
+
|
++ | +|
Using a chain to search for access credentials + |
+You can use this method to search for access keys in a chain in a predefined sequence. The first pair of access keys obtained is used to create an ObsClient instance. +By default, environment variables are checked first and then the ECS agencies are checked to obtain access credentials. You cannot customize the search method or sequence. + |
++ | +|
Other configurations + |
+Configuring only the endpoint + |
+Other than access credentials, only the endpoint is configured. + |
++ | +
Configuring the endpoint and other parameters + |
+In addition to the endpoint, you need to configure the HTTP proxy, Socket timeout, and other parameters. You can use the ObsConfiguration class to configure the ObsClient instance. For details about the supported parameters, see Table 2. + |
++ | +
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 | // Enter the endpoint of the region where the bucket is located. +String endPoint = "https://your-endpoint"; +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(ak, sk, endPoint); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close(); + |
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +String securityToken = System.getenv("SECRET_TOKEN"); +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close(); + |
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(new BasicObsCredentialsProvider(ak, sk), endPoint); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close(); + |
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Create an instance of the ObsConfiguration class. +ObsConfiguration config = new ObsConfiguration(); +config.setEndPoint(endPoint); + +// Create an instance of SecretFlexibleObsClient. +SecretFlexibleObsClient obsClient = new SecretFlexibleObsClient(config); +// Use the instance of SecretFlexibleObsClient to access OBS. +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak1 = System.getenv("ACCESS_KEY_ID"); +String sk1 = System.getenv("SECRET_ACCESS_KEY_ID"); +obsClient.listBuckets(ak1, sk1); + +String ak2 = System.getenv("ACCESS_KEY_ID"); +String sk2 = System.getenv("SECRET_ACCESS_KEY_ID"); +obsClient.listBuckets(ak2, sk2); + +// Close the instance. +obsClient.close(); + |
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(new EnvironmentVariableObsCredentialsProvider(), endPoint); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close(); + |
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(new EcsObsCredentialsProvider(), endPoint); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close(); + |
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(new OBSCredentialsProviderChain(), endPoint); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close(); + |
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 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + +String jksPassword = "you-jks-password"; +String jksPath = "/path/to/your/keystore/file"; +KeyStore ks = KeyStore.getInstance("JKS"); +char[] passArray = jksPassword.toCharArray(); +FileInputStream inputStream = new FileInputStream(jksPath); +ks.load(inputStream, passArray); +KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); +kmf.init(ks, passArray); + +String trustJKSPassword = "you-trustJKS-password"; +String trustJKSPath = "/path/to/your/trustKeyStore/file"; +KeyStore trustKeyStore = KeyStore.getInstance("JKS"); +char[] trustPassArray = trustJKSPassword.toCharArray(); +FileInputStream trustInputStream = new FileInputStream(trustJKSPath); +trustKeyStore.load(trustInputStream, trustPassArray); +TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); +tmf.init(trustKeyStore); + +ObsConfiguration config = new ObsConfiguration(); +config.setEndPoint(endPoint); +config.setKeyManagerFactory(kmf); +config.setTrustManagerFactory(tmf); + +ObsClient obsClient = new ObsClient(ak, sk, config); + |
The local certificate must be stored as a .jks file. You can run the following command to call the Java keytool to convert a .cer certificate into a .jks one:
+keytool -import -file your-cer-file.cer -keystore your-keystore-file.jks
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 | // Enter the endpoint of the region where the bucket is located. + +String endPoint = "https://your-endpoint"; +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + +// The URL cannot contain the protocol header http:// or https://. +String proxyUrl = "proxy.com"; +int proxyPort = 8080; +String proxyUser = "userName"; +String proxyPassword = "password"; +ObsConfiguration config = new ObsConfiguration(); +config.setEndPoint(endPoint); +config.setHttpProxy(proxyUrl, proxyPort, proxyUser, proxyPassword); +ObsClient obsClient = new ObsClient(ak, sk,config); + |
// Specify the user-defined domain name that has been configured on the console. +String endPoint = "http://your-domain"; +// Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console.String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + +// Create an instance of the ObsConfiguration class. +ObsConfiguration config = new ObsConfiguration(); +config.setEndPoint(endPoint); +config.setCname(true); + +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(ak, sk, config); + +// Create an instance of ObsClient using Provider. +// ObsClient obsClient = new ObsClient(new EnvironmentVariableObsCredentialsProvider(), config); +// ObsClient obsClient = new ObsClient(new EcsObsCredentialsProvider(), config); + +// Use the instance to access OBS. + +// Close the instance. +obsClient.close();+
Parameter + |
+Description + |
+Method + |
+Recommended Value + |
+
|---|---|---|---|
connectionTimeout + |
+Explanation: +The amount of time to wait when initially establishing an HTTP/HTTPS connection before giving up and timing out. +Default value: +60000, in milliseconds. + |
+ObsConfiguration.setConnectionTimeout + |
+[10000, 60000] + |
+
socketTimeout + |
+Explanation: +The amount of time to wait for data to be transferred by the socket layer before the transfer times out. +Default value: +60000, in milliseconds. + |
+ObsConfiguration.setSocketTimeout + |
+[10000, 60000] + |
+
idleConnectionTime + |
+Explanation: +If the idle time of a connection exceeds the value of this parameter, the connection is closed. To ensure your services run smoothly, you are advised to set this parameter to a value less than or equal to 30000 ms. +Default value: +30000, in ms. + |
+ObsConfiguration.setIdleConnectionTime + |
+[0, 30000] + |
+
maxIdleConnections + |
+Explanation: +The allowed maximum number of pooled idle connections. +Default value: +1000 + |
+ObsConfiguration.setMaxIdleConnections + |
+Configure this parameter based on your needs. + |
+
maxConnections + |
+Explanation: +The allowed maximum number of concurrent HTTP requests. +Default value: +1000 + |
+ObsConfiguration.setMaxConnections + |
+Default + |
+
maxErrorRetry + |
+Explanation: +The allowed maximum number of retry attempts for failed requests (for example, request exceptions, or 500 or 503 error responses from the server). +Restrictions: +This parameter is invalid if an exception occurs when the data stream of the object to upload or download is being processed. +Default value: +3 + |
+ObsConfiguration.setMaxErrorRetry + |
+[0, 5] + |
+
endPoint + |
+Explanation: +OBS server address. It consists of a protocol type, domain name, and port number, for example, https://your-endpoint:443. For security purposes, you are advised to use HTTPS. +Restrictions: +For DNS resolution and OBS reliability reasons, you are not allowed to specify an IP address for this parameter because this will lead to a path-style request being used, which is prohibited by OBS. You need to use a domain name to specify this parameter. +Default value: +None + |
+ObsConfiguration.setEndPoint + |
+Configure this parameter based on your needs. + |
+
httpProxy + |
+Explanation: +HTTP proxy configuration. +Default value: +This parameter is left blank by default. + |
+ObsConfiguration.setHttpProxy + |
+Configure this parameter based on your needs. + |
+
validateCertificate + |
+Explanation: +Whether to verify the server certificate. +Value range: +
Default value: +false + |
+ObsConfiguration.setValidateCertificate + |
+Configure this parameter based on your needs. + |
+
verifyResponseContentType + |
+Explanation: +Whether to verify the ContentType header in the response. +Value range: +
Default value: +true + |
+ObsConfiguration.setVerifyResponseContentType + |
+Default + |
+
readBufferSize + |
+Explanation: +Size of the buffer used for downloading objects from socket streams. The value -1 indicates that no buffer is configured. +Default value: +-1, in bytes. + |
+ObsConfiguration.setReadBufferSize + |
+Configure this parameter based on your needs. + |
+
writeBufferSize + |
+Explanation: +Size of the buffer used for uploading objects to socket streams. The value -1 indicates that no buffer is configured. +Default value: +-1, in bytes. + |
+ObsConfiguration.setWriteBufferSize + |
+Configure this parameter based on your needs. + |
+
socketWriteBufferSize + |
+Explanation: +Size of the sending buffer of the socket. This parameter corresponds to java.net.SocketOptions.SO_SNDBUF. +Default value: +-1, in bytes, indicating that this parameter is not configured. + |
+ObsConfiguration.setSocketWriteBufferSize + |
+Default + |
+
socketReadBufferSize + |
+Explanation: +Size of the receiving buffer of the socket. This parameter corresponds to java.net.SocketOptions.SO_RCVBUF. +Default value: +-1, in bytes, indicating that this parameter is not configured. + |
+ObsConfiguration.setSocketReadBufferSize + |
+Default + |
+
keyManagerFactory + |
+Explanation: +Factory used for generating javax.net.ssl.KeyManager. +Default value: +This parameter is left blank by default. + |
+ObsConfiguration.setKeyManagerFactory + |
+Configure this parameter based on your needs. + |
+
trustManagerFactory + |
+Explanation: +Factory used for generating javax.net.ssl.TrustManager. +Default value: +This parameter is left blank by default. + |
+ObsConfiguration.setTrustManagerFactory + |
+Configure this parameter based on your needs. + |
+
isStrictHostnameVerification + |
+Explanation: +Whether to strictly verify the server-side host name. If this parameter is set to true, javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier needs to be used to create an object as an implementation of javax.net.ssl.HostnameVerifier to verify the host name. +Value range: +
Default value: +false + |
+ObsConfiguration.setIsStrictHostnameVerification + |
+Configure this parameter based on your needs. + |
+
keepAlive + |
+Explanation: +Whether to use persistent connections to access OBS. +Value range: +
Default value: +true + |
+ObsConfiguration.setKeepAlive + |
+Configure this parameter based on your needs. + |
+
cname + |
+Explanation: +Whether to use a user-defined domain name to access OBS. +Value range: +
Default value: +false + |
+ObsConfiguration.setCname + |
+Configure this parameter based on your needs. + |
+
sslProvider + |
+Explanation: +Provider of the SSLContext. +Default value: +The SSLContext provided by the JDK is used. + |
+ObsConfiguration.setSslProvider + |
+Configure this parameter based on your needs. + |
+
httpProtocolType + |
+Explanation: +HTTP protocol type used for accessing the OBS server. +Default value: +HTTP1.1 + NOTE:
+If the value of endPoint does not contain any protocol, HTTPS is used by default. + |
+ObsConfiguration.setHttpProtocolType + |
+Configure this parameter based on your needs. + |
+
httpDispatcher + |
+Explanation: +User-defined dispatcher. +Default value: +None + |
+ObsConfiguration.setHttpDispatcher + |
+Configure this parameter based on your needs. + |
+
secureRandom + |
+Explanation: +User-defined random number generator. +Default value: +new SecureRandom() + NOTE:
+
|
+ObsConfiguration.setSecureRandom + |
+Configure this parameter based on your needs. + |
+
OBS SDK for Java offers logging based on the open-source Apache Log4j 2 library. By default, the SDK stores WARN log files to the directory specified by the JDK system variable user.dir. You can modify the log configuration file based on your needs.
+
If problems occur when using the OBS Java SDK, you can perform the following steps to analyze and locate the problems.
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 | ObsClient obsClient = null; +try +{ + String endPoint = "https://your-endpoint"; + // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + + obsClient = new ObsClient(ak, sk, endPoint); + HeaderResponse response = obsClient.putObject("bucketname", "objectname", new ByteArrayInputStream("Hello OBS".getBytes())); + // (Optional) If a call is successful, record the HTTP status code and request ID returned by the server. + System.out.println(response.getStatusCode()); + System.out.println(response.getRequestId()); +} +catch (ObsException e) +{ + // Recommended: When an exception occurs, record the HTTP status code, server-side error code, and request ID returned by the server. + System.out.println("HTTP Code: " + e.getResponseCode()); + System.out.println("Error Code:" + e.getErrorCode()); + System.out.println("Request ID:" + e.getErrorRequestId()); + // Recommended: When an exception occurs, record the stack information. + e.printStackTrace(System.out); +} + |
1 +2 | HTTP Code: 403 +Error Code: SignatureDoesNotMatch + |
Possible causes are as follows:
+1 +2 | HTTP Code: 405 +Error Code: MethodNotAllowed + |
This error occurs because a feature on which the ObsClient API depends has not been rolled out on the requested OBS server. Contact the OBS O&M team for further confirmation.
+1 +2 | HTTP Code: 409 +Error Code: BucketAlreadyOwnedByYou + |
In OBS, a bucket name must be globally unique. Solution: If this error occurs when the ObsClient.createBucket is called, check whether the bucket exists. You can use either of the following methods to check whether a bucket exists:
+Method 1 (recommended): Call ObsClient.listBuckets to query the list of all buckets that you own and check whether the bucket exists.
+Method 2: Call ObsClient.headBucket to check whether the bucket exists.
+
ObsClient.headBucket can query only buckets in the current region, while ObsClient.listBuckets can query buckets in all regions.
+1 +2 | HTTP Code: 409 +Error Code: BucketAlreadyExists + |
In OBS, a bucket name must be globally unique. Solution: If this error occurs when ObsClient.createBucket is called, it indicates that the bucket has been created by another user. Use a different bucket name and try again.
+1 +2 +3 +4 | HTTP Code: 408 +Caused by: java.net.ConnectException: Connection timed out: connect + at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) + at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) + |
Possible causes are as follows:
+1 +2 +3 +4 +5 +6 | HTTP Code: 408 +Error Code:RequestTimeOut +Caused by: java.net.SocketTimeoutException: timeout + at okio.Okio$4.newTimeoutException(Okio.java:232) + at okio.AsyncTimeout.exit(AsyncTimeout.java:285) + at okio.AsyncTimeout$2.read(AsyncTimeout.java:241) + |
Possible causes are as follows:
+1 | HTTP Code: -1 + |
Possible causes are as follows:
+Possible causes are as follows:
+1 +2 +3 +4 | Caused by: java.net.UnknownHostException: bucketname.unknowndomain.com + at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) + at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) + at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293) + |
Possible causes are as follows:
+1 +2 +3 | Exception in thread "main" java.lang.NullPointerException + at com.obs.services.internal.RestStorageService.isCname(RestStorageService.java:1213) + at com.obs.services.ObsClient.doActionWithResult(ObsClient.java:2805) + |
Possible causes are as follows:
+1 | A connection to xxx was leaked. Did you forget to close a response body? + |
This error occurs when ObsClient.getObject is not properly closed after it is called to obtain the data stream of the object to be downloaded. To fix this error, call the ObsObject.getObjectContent.close method in the finally statement block to close the connection.
+The third-party dependency of the SDK of an earlier version (2.1.x) is not completely compatible with that of the new SDK (3.x). If a program startup error occurs after the earlier version is upgraded to the new version, refer to Resolving Dependency Missing or Conflicts to rectify the fault. If the fault persists, contact the OBS O&M team.
+1 +2 +3 +4 +5 +6 | Exception in thread "main" java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)' + at com.obs.services.internal.RestConnectionService.createRequestBuilder(RestConnectionService.java:157) + at com.obs.services.internal.RestConnectionService.setupConnection(RestConnectionService.java:148) + at com.obs.services.internal.RestConnectionService.setupConnection(RestConnectionService.java:124) + at com.obs.services.internal.RestStorageService.performRequest(RestStorageService.java:395) + at com.obs.services.internal.RestStorageService.performRequest(RestStorageService.java:388) + |
This error occurs because OkHttp of an earlier version was used after the SDK upgrade. To resolve this issue, upgrade OkHttp to a required version by referring to Resolving Dependency Missing or Conflicts.
+1 +2 +3 +4 +5 +6 +7 +8 +9 | Caused by: java.lang.StackOverflowError + at sun.misc.URLClassPath.getResource(URLClassPath.java:211) ~[?:1.8.0_91] + at java.net.URLClassLoader$1.run(URLClassLoader.java:365) ~[?:1.8.0_91] + at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[?:1.8.0_91] + at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_91] + at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[?:1.8.0_91] + at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_91] + at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_91] + at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1806) + |
Check the JVM parameter xss and set it to 1 MB. xss indicates the memory size allocated to each thread started by the JVM. By default, the value of xss is 256 KB for JDK 1.4 and 1 MB for JDK 1.5 or later.
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 | javax.net.ssl.SSLException: SSL peer shut down incorrectly + at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:596) + at sun.security.ssl.InputRecord.read(InputRecord.java:532) + at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975) + at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:933) + at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) + at obs.shaded.okio.Okio$2.read(Okio.java:140) + at obs.shaded.okio.AsyncTimeout$2.read(AsyncTimeout.java:237) + at obs.shaded.okio.RealBufferedSource.read(RealBufferedSource.java:51) + at obs.shaded.okhttp3.internal.http1.Http1ExchangeCodec$AbstractSource.read(Http1ExchangeCodec.java:389) + at obs.shaded.okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.java:427) + at obs.shaded.okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286) + at obs.shaded.okio.RealBufferedSource$1.read(RealBufferedSource.java:447) + at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:238) + at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158) + at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:117) + at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) + at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) + at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) + at java.io.InputStreamReader.read(InputStreamReader.java:184) + at java.io.BufferedReader.fill(BufferedReader.java:161) + at java.io.BufferedReader.readLine(BufferedReader.java:324) + at java.io.BufferedReader.readLine(BufferedReader.java:389) + |
Do not read file streams by line during a download on the client. For details, see the demo for a streaming download.
+For details, see FAQs.
+Dependency missing and dependency conflict are commonly encountered in Java development or during SDK integration. If error message "ClassNotFoundException" or "NoClassDefFoundError" is reported during application compilation and running, check whether this is a dependency-triggered problem. If yes, perform the following steps to locate and rectify the fault.
+The following table lists the third-party components (including their versions) that the latest SDK depends on.
+Dependency + |
+Version + |
+Description + |
+
|---|---|---|
okhttp + |
+4.11.0 + |
+Used to send HTTP requests. + |
+
okio + |
+3.5.0 + |
+Component of OkHttp + |
+
java-xmlbuilder + |
+1.3 + |
+Used to construct and parse XML files. + |
+
jackson-core + |
+2.13.3 + |
+Used to construct and parse JSON files. + |
+
jackson-databind + |
+2.15.0 + |
+Component of jackson-core + |
+
jackson-annotations + |
+2.13.3 + |
+Component of jackson-core + |
+
If your project has multiple versions of OBS Java SDK packages or third-party dependencies, dependency conflicts may occur. If there are SDKs of earlier versions, delete them and use the latest version. If there are multiple versions of third-party dependencies, replace the conflict ones with the versions required by the SDK.
+This API creates an OBS bucket. Buckets are containers for storing objects (files uploaded to OBS) in OBS.
+When creating a bucket, you can also configure parameters such as the storage class, region, and access control list (ACL) as needed.
+createBucket(CreateBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for creating a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
location + |
+String + |
+Yes if the region where the OBS service resides is not the default region + |
+Explanation: +Region where a bucket will be located +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
acl + |
++ | +No + |
+Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
storageClass + |
++ | +No + |
+Explanation: +Bucket storage class that can be specified at bucket creation. +Value range: +See Table 12. +Default value: +STANDARD + |
+
extensionPermissionMap + |
+Map<ExtensionBucketPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionBucketPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
epid + |
+String + |
+No + |
+Explanation: +Enterprise project ID that can be specified at bucket creation. If you have enabled Enterprise Project Management Service (EPS), you can obtain the project ID from the EPS console. +Restrictions: +The value of epid is a Universally Unique Identifier (UUID). epid is not required if you have not enabled EPS yet. +Example: 9892d768-2d13-450f-aac7-ed0e44c2585f +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants the READ permission to an account ID. +The account with the READ permission can list objects, multipart uploads, and object versions in the bucket you are creating, and can obtain bucket metadata. + |
+
GRANT_WRITE + |
+Grants the WRITE permission to an account ID. +The account with the WRITE permission can create, delete, and overwrite objects in the bucket you are creating, and can initiate or abort multipart uploads, as well as upload, copy, and assemble parts. + |
+
GRANT_READ_ACP + |
+Grants the READ_ACP permission to an account ID. +The account with the READ_ACP permission can read the ACL of the bucket you are creating. + |
+
GRANT_WRITE_ACP + |
+Grants the WRITE_ACP permission to an account ID. +The account with the WRITE_ACP permission can modify the ACL of the bucket you are creating. + |
+
GRANT_FULL_CONTROL + |
+Grants the FULL_CONTROL permission to an account ID. +The account with the FULL_CONTROL permission can perform any operation on the bucket you are creating. + |
+
GRANT_READ_DELIVERED + |
+Grants the READ permission to an account ID. By default, this READ permission applies to all objects in the bucket. + |
+
GRANT_FULL_CONTROL_DELIVERED + |
+Grants the FULL_CONTROL permission to an account ID. By default, this FULL_CONTROL permission applies to all objects in the bucket. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 6. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 7. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 8. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +For details, see Table 11. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 9. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +For details, see Table 10. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
owner + |
++ | +Explanation: +Bucket owner information. For details, see Table 6. + |
+
creationDate + |
+java.util.Date + |
+Explanation: +Time when the bucket was created. +Default value: +None + |
+
location + |
+String + |
+Explanation: +Region where a bucket will be located +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
storageClass + |
++ | +Explanation: +Bucket storage class that can be specified at bucket creation. +Value range: +See Table 12. +Default value: +STANDARD + |
+
acl + |
++ | +Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
This example creates a bucket and configures its ACL, storage class, and region.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.AvailableZoneEnum; +import com.obs.services.model.CreateBucketRequest; +import com.obs.services.model.ObsBucket; +import com.obs.services.model.StorageClassEnum; + +public class CreateBucket001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + CreateBucketRequest request = new CreateBucketRequest(); + // Example bucket name + String exampleBucket = "examplebucket"; + // Example bucket location + request.setBucketName(exampleBucket); + // Set the bucket ACL to Private (the default value). + request.setAcl(AccessControlList.REST_CANNED_PRIVATE); + // Set the bucket storage class to Standard. + request.setBucketStorageClass(StorageClassEnum.STANDARD); + request.setLocation(exampleLocation); + // Create a bucket. + ObsBucket bucket = obsClient.createBucket(request); + // The bucket is created. + System.out.println("CreateBucket successfully"); + System.out.println("RequestId:"+bucket.getRequestId()); + + + } catch (ObsException e) { + System.out.println("CreateBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("CreateBucket failed"); + // Print other error information. + e.printStackTrace(); + + } + } +} + |
This example creates a bucket and specifies its name and endpoint.
+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 +49 +50 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsBucket; + +public class CreateBucket002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Create a bucket. + ObsBucket bucket = obsClient.createBucket(exampleBucket); + System.out.println("CreateBucket successfully"); + System.out.println("StatusCode: " + bucket.getStatusCode()); + System.out.println("RequestId: " + bucket.getRequestId()); + } catch (ObsException e) { + System.out.println("CreateBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("CreateBucket failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS buckets are containers for storing objects you upload to OBS. This API returns a list of all buckets that meet the specified conditions in all regions of the current account. Returned buckets are listed in alphabetical order by bucket name.
+obsClient.listBuckets(ListBucketsRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for listing buckets. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
queryLocation + |
+boolean + |
+No + |
+Explanation: +Whether to query the bucket location +Value range: +
Default value: +false + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
owner + |
++ | +Explanation: +Bucket owner information. For details, see Table 4. +Default value: +None + |
+
buckets + |
+List<ObsBucket> + |
+Explanation: +Bucket list information. For details, see Table 13. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class. + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 4. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 7. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 8. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 11. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 9. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 10. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
owner + |
++ | +Explanation: +Bucket owner information. For details, see Table 4. + |
+
creationDate + |
+java.util.Date + |
+Explanation: +Time when the bucket is created. +Default value: +None + |
+
location + |
+String + |
+Explanation: +Region where a bucket is located +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
storageClass + |
++ | +Explanation: +Bucket storage class that can be specified at bucket creation. +Value range: +See Table 5. +Default value: +STANDARD + |
+
acl + |
++ | +Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
This example lists all buckets and queries the bucket regions.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListBucketsRequest; +import com.obs.services.model.ObsBucket; +import java.util.List; +public class ListBucket001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List buckets. + ListBucketsRequest request = new ListBucketsRequest(); + request.setQueryLocation(true); + List<ObsBucket> buckets = obsClient.listBuckets(request); + for (ObsBucket bucket : buckets) { + System.out.println("ListBuckets successfully"); + System.out.println("BucketName:" + bucket.getBucketName()); + System.out.println("CreationDate:" + bucket.getCreationDate()); + System.out.println("Location:" + bucket.getLocation()); + } + } catch (ObsException e) { + System.out.println("ListBuckets failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("ListBuckets failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API deletes an empty bucket. You can delete buckets you no longer use to free up space. The name of a deleted bucket can be reused for another bucket at least 30 minutes after the deletion.
+obsClient.deleteBucket(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes bucket exampleBucket.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HeaderResponse; +public class DeleteBucket001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Delete the bucket. + HeaderResponse response = obsClient.deleteBucket(exampleBucket); + System.out.println("DeleteBucket successfully"); + System.out.println("StatusCode:"+response.getStatusCode()); + System.out.println("RequestId:"+response.getRequestId()); + } catch (ObsException e) { + System.out.println("DeleteBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("DeleteBucket failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API checks whether a bucket exists. If an HTTP status code 200 is returned, the bucket exists. If 404 is returned, the bucket does not exist.
+obsClient.headBucket(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
boolean + |
+Explanation: +Whether the bucket exists +Value range: +true: The bucket exists. +false: The bucket does not exist. +Default value: +None + |
+
This example checks whether bucket examplebucket exists.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class HeadBucket { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Check whether the bucket exists. + boolean exists = obsClient.headBucket(exampleBucket); + System.out.println("HeadBucket successfully"); + System.out.println(exists); + } catch (ObsException e) { + System.out.println("HeadBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code :" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("HeadBucket failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns information about a bucket, including the storage class, region, CORS rules, and redundancy policy.
+obsClient.getBucketMetadata(BucketMetadataInfoRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for obtaining bucket metadata. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
origin + |
+String + |
+No + |
+Explanation: +Origin of the cross-domain request specified by the preflight request. Generally, it is a domain name. +Restrictions: +You can configure one or more rules and use at most one wildcard character (*) in each rule. If you want to configure multiple rules, separate them using a line breaker. +Default value: +None + |
+
requestHeaders + |
+List<String> + |
+No + |
+Explanation: +HTTP headers in a cross-origin request. Only CORS requests matching the allowed headers are valid. +Restrictions: +You can enter multiple allowed headers, with one separated from another using a line break. Each header can contain one wildcard character (*) at most. Spaces, ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. Default value: +None + |
+
location + |
+String + |
+Explanation: +Region where a bucket is located. +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
obsVersion + |
+String + |
+Explanation: +OBS version of the bucket. +Value range: +
Default value: +None + |
+
storageClass + |
++ | +Explanation: +Bucket storage class that can be specified at bucket creation. +Value range: +See Table 4. +Default value: +STANDARD + |
+
allowOrigin + |
+String + |
+Explanation: +If Origin in the request meets the CORS rules of the bucket, AllowedOrigin specified in the CORS rules is returned. +Restrictions: +You can configure one or more rules and use at most one wildcard character (*) in each rule. If you want to configure multiple rules, separate them using a line breaker. +Default value: +None + |
+
allowHeaders + |
+List<String> + |
+Explanation: +If RequestHeader in the request meets the CORS rules of the bucket, AllowedHeader specified in the CORS rules is returned. +Restrictions: +You can enter multiple allowed headers, with one separated from another using a line break. Each header can contain one wildcard character (*) at most. Spaces, ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
allowMethods + |
+List<String> + |
+Explanation: +The allowed HTTP methods for a cross-origin request, indicating the operation types of buckets and objects. +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
exposeHeaders + |
+List<String> + |
+Explanation: +The CORS-allowed additional headers in the response. These headers provide additional information to clients. By default, your browser can only access headers Content-Length and Content-Type. If your browser needs to access other headers, add them to the list of the allowed additional headers. +Restrictions: +Spaces, wildcard characters (*), ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
maxAge + |
+int + |
+Explanation: +Time your client can cache the response for a cross-origin request +Restrictions: +Each CORS rule can contain only one maxAge. +Value range: +An integer greater than 0, in seconds +Default value: +100 + |
+
epid + |
+String + |
+Explanation: +Enterprise project ID that can be specified at bucket creation. If you have enabled EPS, you can obtain the project ID from the EPS console. +Restrictions: +The value of Epid is a UUID. If the default enterprise project is used, 0 is passed here or Epid is not included. Epid is not required for those who have not enabled the EPS. +Example: 9892d768-2d13-450f-aac7-ed0e44c2585f +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class. + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
This example obtains the metadata of bucket examplebucket. The origin of the cross-origin request is http://www.exampleorigin.com.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketMetadataInfoRequest; +import com.obs.services.model.BucketMetadataInfoResult; +public class GetBucketMetadata001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + //Example origin + String exampleOrigin = "http://www.exampleorigin.com"; + BucketMetadataInfoRequest request = new BucketMetadataInfoRequest(exampleBucket); + // Specify setOrigin only when cross origin resource sharing (CORS) is used. + request.setOrigin(exampleOrigin); + // Obtain the bucket metadata. + BucketMetadataInfoResult result = obsClient.getBucketMetadata(request); + System.out.println("GetBucketMetadata successfully"); + System.out.println("GetBucketType:" + result.getBucketType()); + System.out.println("GetLocation:" + result.getLocation()); + System.out.println("GetBucketStorageClass:" + result.getBucketStorageClass()); + System.out.println("GetObsVersion:" + result.getObsVersion()); + System.out.println("GetAllowOrigin:" + result.getAllowOrigin()); + System.out.println("GetMaxAge:" + result.getMaxAge()); + System.out.println("GetAllowHeaders:" + result.getAllowHeaders()); + System.out.println("GetAllowMethods:" + result.getAllowMethods()); + System.out.println("GetExposeHeaders:" + result.getExposeHeaders()); + } catch (ObsException e) { + System.out.println("GetBucketMetadata failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketMetadata failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over resources when a bucket or object is created. That is, the bucket creator has full control over the bucket, and the object uploader has full control over the object. Other accounts do not have the permissions to access resources. If resource owners want to grant other accounts the read and write permissions on resources, they can use ACLs. ACLs grant permissions to accounts. After an account is granted permissions, both the account and its IAM users can access the resources.
+ +You can configure a bucket ACL by referring to Method.
+obsBucket.setBucketName(exampleBucket); +// Set the bucket ACL to private read and write. +obsBucket.setAcl(AccessControlList.REST_CANNED_PRIVATE); +// Create a bucket. +obsClient.createBucket(obsBucket);+
// Set the bucket ACL to private read and write. +obsClient.setBucketAcl(String exampleBucket, AccessControlList.REST_CANNED_PRIVATE);+
// Set a user-defined ACL for the bucket. +obsClient.setBucketAcl(String bucketName,AccessControlList acl);+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
acl + |
++ | +Yes + |
+Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +Yes + |
+Explanation: +Bucket owner information. For details, see Table 4. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 5. + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 6. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 9. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 7. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 8. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures a pre-defined ACL during the creation of bucket exampleBucket.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.ObsBucket; +public class SetBucketAcl001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + ObsBucket obsBucket = new ObsBucket(); + // Example bucket name + String exampleBucket = "examplebucket"; + obsBucket.setBucketName(exampleBucket); + // Set the bucket ACL to private read and write. + obsBucket.setAcl(AccessControlList.REST_CANNED_PRIVATE); + // Create a bucket. + obsClient.createBucket(obsBucket); + System.out.println("SetBucketAcl successfully"); + } catch (ObsException e) { + System.out.println("SetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("SetBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example configures a pre-defined ACL for bucket exampleBucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +public class SetBucketAcl002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Set the bucket ACL to private read and write. + obsClient.setBucketAcl(exampleBucket, AccessControlList.REST_CANNED_PRIVATE); + System.out.println("SetBucketAcl successfully"); + } catch (ObsException e) { + System.out.println("SetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("SetBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example defines an ACL for the exampleBucket bucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.CanonicalGrantee; +import com.obs.services.model.GroupGrantee; +import com.obs.services.model.Owner; +import com.obs.services.model.Permission; +public class SetBucketAcl003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Example user ID + String exampleUserid = "userid"; + // Example user ID + String exampleOwnerId = "ownerid"; + AccessControlList acl = new AccessControlList(); + Owner owner = new Owner(); + owner.setId(exampleOwnerId); + acl.setOwner(owner); + // Grant the full control permission to a specified user. + acl.grantPermission(new CanonicalGrantee(exampleUserid), Permission.PERMISSION_FULL_CONTROL); + // Grant the read permission to all users. + acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ); + // Set the bucket ACL. + obsClient.setBucketAcl(exampleBucket, acl); + System.out.println("SetBucketAcl successfully"); + } catch (ObsException e) { + System.out.println("SetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("SetBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example directly configures an ACL for bucket exampleBucket and applies this ACL to the objects in the bucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.CanonicalGrantee; +import com.obs.services.model.GroupGrantee; +import com.obs.services.model.Owner; +import com.obs.services.model.Permission; +public class SetBucketAcl004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an instance of ObsClient. + // Use a permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use a temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + //Example bucket name + String exampleBucket = "examplebucket"; + //Example user ID + String exampleUserid = "userid"; + //Example owner ID + String exampleOwnerId = "ownerid"; + AccessControlList acl = new AccessControlList(); + Owner owner = new Owner(); + owner.setId(exampleOwnerId); + acl.setOwner(owner); + // Grant the full control permission to a specific user. The bucket ACL also applies to the objects in the bucket. + acl.grantPermission(new CanonicalGrantee(exampleUserid), Permission.PERMISSION_FULL_CONTROL,true); + // Grant the read permission to all users. The bucket ACL also applies to the objects in the bucket. + acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ,true); + // Set the bucket ACL. + obsClient.setBucketAcl(exampleBucket, acl); + System.out.println("SetBucketAcl successfully"); + } catch (ObsException e) { + System.out.println("SetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("SetBucketAcl failed"); + // Print other error details. + e.printStackTrace(); + } + } +} + |
OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control can be implemented using IAM permissions, bucket policies, and ACLs.
+A bucket policy applies to both the bucket and objects therein. You can use a bucket policy to grant permissions for a bucket and objects therein to IAM users or other accounts. If you want IAM users to have different permissions for different buckets, you need to configure different bucket policies for those users.
+Besides bucket ACLs, bucket owners can use bucket policies to centrally control access to buckets and objects in buckets.
+You can call ObsClient.setBucketPolicy to configure a bucket policy.
+obsClient.setBucketPolicy(String bucketName, String policy)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
policy + |
+String + |
+Yes + |
+Explanation: +Policy information in JSON format +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures a policy for bucket exampleBucket.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class SetBucketPolicy001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Example bucket policy + String examplePolicy = + "{\"Statement\":[{\"Principal\":\"*\",\"Effect\":\"Allow\",\"Action\":\"ListBucket\",\"Resource\":\"" + + exampleBucket + + "\"}]}"; + obsClient.setBucketPolicy(exampleBucket, examplePolicy); + System.out.println("SetBucketAcl successfully"); + } catch (ObsException e) { + System.out.println("SetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("SetBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the region where a bucket is located.
+obsClient.getBucketLocation(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
location + |
+String + |
+Explanation: +Region where a bucket is located. +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
This example returns the region where bucket exampleBucket locates.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class GetBucketLocation001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Obtain the bucket region. + String location = obsClient.getBucketLocation(exampleBucket); + System.out.println("GetBucketLocation successfully"); + System.out.println("Location:" + location); + } catch (ObsException e) { + System.out.println("GetBucketLocation failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketLocation failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the storage information of a bucket, including the number of objects and the space occupied by the objects in the bucket.
+
OBS measures bucket storage statistics in the background and does not update the storage information in real time. So, you are advised not to perform real-time verification on the storage information.
+obsClient.getBucketStorageInfo(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
size + |
+long + |
+Explanation: +Size of the space occupied by objects in the bucket. +Value range: +A non-negative integer, in bytes. +Default value: +None + |
+
objectNum + |
+long + |
+Explanation: +Number of objects in the bucket. +Default value: +None + |
+
This example returns the storage information of bucket exampleBucket.
+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 +49 +50 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketStorageInfo; +public class GetBucketStorageInfo001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Obtain the bucket storage information. + BucketStorageInfo storageInfo = obsClient.getBucketStorageInfo(exampleBucket); + System.out.println("GetBucketStorageInfo successfully"); + System.out.println("GetObjectNumber:" + storageInfo.getObjectNumber()); + System.out.println("GetStorageSize:" + storageInfo.getSize() + " bytes"); + } catch (ObsException e) { + System.out.println("GetBucketStorageInfo failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketStorageInfo failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
A quota limits the maximum capacity allowed in a bucket. By default, there is no limit on the storage capacity of the entire OBS system or a single bucket, and any number of objects can be stored. You can set a storage quota to control the total size of objects that can be uploaded to the bucket. After the storage quota has been reached, object upload will fail.
+A quota limit does not apply to the objects uploaded before the quota is configured. If the specified quota is already smaller than the total size of existing objects in the bucket, the existing objects in the bucket will not be deleted, but no more object can be uploaded to the bucket later. In this case, to upload new objects, you must delete some of the existing objects to make the used space below the quota limit.
+obsClient.setBucketQuota(String bucketName, BucketQuota bucketQuota)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
bucketQuota + |
++ | +Yes + |
+Explanation: +Bucket quota information +Restrictions: +See Table 2. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures a quota for bucket exampleBucket.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketQuota; +public class SetBucketQuota001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Example bucket quota + long exampleBucketQuota = 1024 * 1024 * 100L; + // Set the bucket quota to 100 MB. + BucketQuota quota = new BucketQuota(exampleBucketQuota); + obsClient.setBucketQuota(exampleBucket, quota); + System.out.println("SetBucketQuota successfully"); + } catch (ObsException e) { + System.out.println("SetBucketQuota failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("SetBucketQuota failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API configures a storage class for a bucket. If you do not specify a storage class when uploading or copying an object, or initiating a multipart upload, the object inherits the bucket's storage class.
+The following table lists the three available storage classes.
+ +Storage Class + |
+Description + |
+Value in OBS Java SDK + |
+
|---|---|---|
Standard + |
+Features low access latency and high throughput and is used for storing massive, frequently accessed (multiple times a month) or small objects (< 1 MB) requiring quick response. + |
+StorageClassEnum.STANDARD + |
+
obsClient.setBucketStoragePolicy(String bucketName, BucketStoragePolicyConfiguration bucketStorage)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
bucketStorage + |
+BucketStoragePolicyConfiguration +(Inheriting HeaderResponse) + |
+Yes + |
+Explanation: +Storage class of the bucket. +Value range: +See Table 2. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
storageClass + |
++ | +Explanation: +Storage class of the bucket. +Value range: +See Table 3. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures a storage class for bucket exampleBucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.AvailableZoneEnum; +import com.obs.services.model.CreateBucketRequest; +import com.obs.services.model.ObsBucket; +import com.obs.services.model.StorageClassEnum; + +public class CreateBucket001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + CreateBucketRequest request = new CreateBucketRequest(); + // Example bucket name + String exampleBucket = "examplebucket"; + // Example bucket location + request.setBucketName(exampleBucket); + // Set the bucket ACL to Private (the default value). + request.setAcl(AccessControlList.REST_CANNED_PRIVATE); + // Set the bucket storage class to Standard. + request.setBucketStorageClass(StorageClassEnum.STANDARD); + request.setLocation(exampleLocation); + // Create a bucket. + ObsBucket bucket = obsClient.createBucket(request); + // The bucket is created. + System.out.println("CreateBucket successfully"); + System.out.println("RequestId:"+bucket.getRequestId()); + + + } catch (ObsException e) { + System.out.println("CreateBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("CreateBucket failed"); + // Print other error information. + e.printStackTrace(); + + } + } +} + |
Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over resources when a bucket or object is created. That is, the bucket creator has full control over the bucket, and the object uploader has full control over the object. Other accounts do not have the permissions to access resources. If resource owners want to grant other accounts the read and write permissions on resources, they can use ACLs. ACLs grant permissions to accounts. After an account is granted permissions, both the account and its IAM users can access the resources.
+ +This API returns the ACL of a bucket.
+obsClient.getBucketAcl(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +Yes + |
+Explanation: +Bucket owner information. For details, see Table 3. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 5. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 8. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 6. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 7. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
This example obtains the ACL of the examplebucket bucket.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +public class GetBucketAcl001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + //Obtain the bucket ACL. + AccessControlList acl = obsClient.getBucketAcl(exampleBucket); + System.out.println("GetBucketAcl successfully"); + System.out.println(acl); + } catch (ObsException e) { + System.out.println("GetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control can be implemented using IAM permissions, bucket policies, and ACLs. For more information, see .
+This API returns the policy of a bucket.
+obsClient.getBucketPolicy(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
policy + |
+String + |
+Explanation: +Policy information in JSON format +Restrictions: +
Default value: +None + |
+
This example returns the policy of bucket exampleBucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class GetBucketPolicy001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + String policy = obsClient.getBucketPolicy(exampleBucket); + System.out.println("\t" + policy); + } catch (ObsException e) { + System.out.println("GetBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS provides access control over buckets. You can use an access policy to define whether a user can perform certain operations on a specific bucket. OBS access control can be implemented using IAM permissions, bucket policies, and ACLs. For more information, see .
+You can call ObsClient.deleteBucketPolicy to delete the policy of a bucket. OBS returns 204 No Content if the deletion is successful or the requested bucket policy does not exist.
+obsClient.deleteBucketPolicy(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes the policy of bucket exampleBucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteBucketPolicy001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + obsClient.deleteBucketPolicy(exampleBucket); + } catch (ObsException e) { + System.out.println("DeleteBucketAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("DeleteBucketAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the storage quota (upper limit of the storage capacity) of a bucket. If the quota is 0, there is no upper limit on the bucket capacity.
+obsClient.getBucketQuota(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketQuota + |
+long + |
+Yes + |
+Explanation: +Bucket quota. +Value range: +A non-negative integer, in bytes. +Default value: +0, indicating that there is no limit on the bucket quota. + |
+
This example returns the quota of bucket exampleBucket.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketQuota; +public class GetBucketQuota001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Obtain the bucket quota. + BucketQuota quota = obsClient.getBucketQuota(exampleBucket); + System.out.println("GetBucketQuota successfully"); + System.out.println("GetBucketQuota:" + quota.getBucketQuota() + " bytes"); + } catch (ObsException e) { + System.out.println("GetBucketQuota failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketQuota failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the storage class of a bucket.
+obsClient.getBucketStoragePolicy(String bucketName)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
storageClass + |
++ | +Explanation: +Storage class of the bucket. For details, see Table 3. + |
+
This example configures a storage class for bucket exampleBucket.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketStoragePolicyConfiguration; +public class GetBucketStoragePolicy001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Example bucket name + String exampleBucket = "examplebucket"; + // Obtain the bucket's storage class. + BucketStoragePolicyConfiguration storagePolicy = obsClient.getBucketStoragePolicy(exampleBucket); + System.out.println("GetBucketStoragePolicy successfully"); + System.out.println("GetBucketStorageClass:" + storagePolicy.getBucketStorageClass()); + } catch (ObsException e) { + System.out.println("GetBucketStoragePolicy failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetBucketStoragePolicy failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API configures an inventory rule for the bucket. With this API, object information in a bucket (source) is regularly listed and saved as CSV files. These files are then stored in a specified bucket (destination). In this manner, you can easily manage objects in a bucket. A source bucket can also be the destination bucket. A bucket inventory file contains the following object-related information: object versions, sizes, storage classes, tags, encryption statuses, and last modification time.
+You can encrypt bucket inventory files using SSE-KMS.
+obsClient.setInventoryConfiguration(SetInventoryConfigurationRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
inventoryConfiguration + |
++ | +Yes + |
+Explanation: +Inventory configurations for a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
configurationId + |
+String + |
+Yes + |
+Explanation: +ID of a bucket inventory rule. +Restrictions: +The rule ID allows letters (a–z, A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). +Value range: +The value can be up to 64 characters long. +Default value: +None + |
+
isEnabled + |
+boolean + |
+Yes + |
+Explanation: +Whether the bucket inventory rule is enabled. +Value range: +true: The rule is enabled, and an inventory file is generated. +false: The rule is disabled. No inventory file is generated. +Default value: +true + |
+
objectPrefix + |
+String + |
+No + |
+Explanation: +Used to filter objects. Only objects with the specified name prefix are included in the inventory. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
frequency + |
+String + |
+Yes + |
+Explanation: +Intervals when inventories are generated. You can set this parameter to Daily or Weekly. An inventory is generated within one hour from when it is configured for the first time. Then it is generated at the specified intervals. +Value range: +Daily: Inventories are generated once a day. +Weekly: Inventories are generated once a week. +Default value: +None + |
+
inventoryFormat + |
+String + |
+Yes + |
+Explanation: +Inventory file format. Only the CSV format is supported. +Value range: +CSV +Default value: +None + |
+
destinationBucket + |
+String + |
+Yes + |
+Explanation: +Name of the bucket for storing inventories. +Restrictions: +
Default value: +None + |
+
inventoryPrefix + |
+String + |
+No + |
+Explanation: +The prefix of the inventory file name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +If you do not specify this parameter, BucketInventory is used as the prefix by default. + |
+
includedObjectVersions + |
+String + |
+Yes + |
+Explanation: +Whether versions of objects are included in an inventory. +Value range: +
Default value: +None + |
+
optionalFields + |
+ArrayList<String> + |
+No + |
+Explanation: +Additional object metadata fields that are contained in an inventory file. +Value range: +Size: Object size. +LastModifiedDate: Last time when the object was modified. +StorageClass: The storage class of the object. +ETag: The ETag value of the object. +IsMultipartUploaded: Whether the object was uploaded in a multipart upload. +ReplicationStatus: The cross-region replication status of the object. +EncryptionStatus: The encryption status of the object. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures an inventory for bucket example-bucket to list objects with the name prefix exampleObjectPrefix. The inventory files are stored in bucket example-target-bucket and the name prefix of the inventory files is exampleInventoryPrefix.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HeaderResponse; +import com.obs.services.model.inventory.InventoryConfiguration; +import com.obs.services.model.inventory.SetInventoryConfigurationRequest; +public class SetInventoryConfiguration001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the following parameters. + String exampleBucketName = "example-bucket"; + String exampleTargetBucketName = "example-target-bucket"; + String exampleConfigurationId = "exampleConfigId001"; + String exampleInventoryPrefix = "exampleInventoryPrefix"; + String exampleObjectPrefix = "exampleObjectPrefix"; + // Set parameters for the inventory rule. + InventoryConfiguration exampleConfiguration = new InventoryConfiguration(); + exampleConfiguration.setDestinationBucket(exampleTargetBucketName); + exampleConfiguration.setConfigurationId(exampleConfigurationId); + exampleConfiguration.setInventoryFormat(InventoryConfiguration.InventoryFormatOptions.CSV); + exampleConfiguration.setFrequency(InventoryConfiguration.FrequencyOptions.DAILY); + exampleConfiguration.setEnabled(true); + exampleConfiguration.setIncludedObjectVersions( + InventoryConfiguration.IncludedObjectVersionsOptions.CURRENT); + exampleConfiguration.setInventoryPrefix(exampleInventoryPrefix); + exampleConfiguration.setObjectPrefix(exampleObjectPrefix); + // Set additional metadata fields that will be contained in the inventory file. + exampleConfiguration + .getOptionalFields() + .add(InventoryConfiguration.OptionalFieldOptions.IS_MULTIPART_UPLOADED); + exampleConfiguration.getOptionalFields().add(InventoryConfiguration.OptionalFieldOptions.ETAG); + exampleConfiguration + .getOptionalFields() + .add(InventoryConfiguration.OptionalFieldOptions.REPLICATION_STATUS); + SetInventoryConfigurationRequest request = + new SetInventoryConfigurationRequest(exampleBucketName, exampleConfiguration); + // Set the inventory rule. + HeaderResponse response = obsClient.setInventoryConfiguration(request); + System.out.println("SetInventoryConfiguration succeeded"); + System.out.println("HTTP Code: " + response.getStatusCode()); + } catch (ObsException e) { + System.out.println("SetInventoryConfiguration failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("SetInventoryConfiguration failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns an inventory rule (identified by configurationId) for the bucket.
+obsClient.getInventoryConfiguration(GetInventoryConfigurationRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
configurationId + |
+String + |
+Yes + |
+Explanation: +ID of the inventory rule. +Restrictions: +The ID can be up to 64 bytes long and allows letters (a–z, A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
inventoryConfiguration + |
++ | +Explanation: +Bucket inventory configurations. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
configurationId + |
+String + |
+Yes + |
+Explanation: +ID of a bucket inventory rule. +Restrictions: +The rule ID allows letters (a–z, A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). +Value range: +The value can be up to 64 characters long. +Default value: +None + |
+
isEnabled + |
+boolean + |
+Yes + |
+Explanation: +Whether the bucket inventory rule is enabled. +Value range: +true: The rule is enabled, and an inventory file is generated. +false: The rule is disabled. No inventory file is generated. +Default value: +true + |
+
objectPrefix + |
+String + |
+No + |
+Explanation: +Used to filter objects. Only objects with the specified name prefix are included in the inventory. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
frequency + |
+String + |
+Yes + |
+Explanation: +Intervals when inventories are generated. You can set this parameter to Daily or Weekly. An inventory is generated within one hour from when it is configured for the first time. Then it is generated at the specified intervals. +Value range: +Daily: Inventories are generated once a day. +Weekly: Inventories are generated once a week. +Default value: +None + |
+
inventoryFormat + |
+String + |
+Yes + |
+Explanation: +Inventory file format. Only the CSV format is supported. +Value range: +CSV +Default value: +None + |
+
destinationBucket + |
+String + |
+Yes + |
+Explanation: +Name of the bucket for storing inventories. +Restrictions: +
Default value: +None + |
+
inventoryPrefix + |
+String + |
+No + |
+Explanation: +The prefix of the inventory file name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +If you do not specify this parameter, BucketInventory is used as the prefix by default. + |
+
includedObjectVersions + |
+String + |
+Yes + |
+Explanation: +Whether versions of objects are included in an inventory. +Value range: +
Default value: +None + |
+
optionalFields + |
+ArrayList<String> + |
+No + |
+Explanation: +Additional object metadata fields that are contained in an inventory file. +Value range: +Size: Object size. +LastModifiedDate: Last time when the object was modified. +StorageClass: The storage class of the object. +ETag: The ETag value of the object. +IsMultipartUploaded: Whether the object was uploaded in a multipart upload. +ReplicationStatus: The cross-region replication status of the object. +EncryptionStatus: The encryption status of the object. +Default value: +None + |
+
This example returns the inventory rule whose ID is exampleConfigId001 for bucket example-bucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.inventory.GetInventoryConfigurationRequest; +import com.obs.services.model.inventory.GetInventoryConfigurationResult; +import com.obs.services.model.inventory.InventoryConfiguration; +public class GetInventoryConfiguration001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the following parameters. + String exampleBucketName = "example-bucket"; + String exampleConfigurationId = "exampleConfigId001"; + GetInventoryConfigurationRequest request = + new GetInventoryConfigurationRequest(exampleBucketName, exampleConfigurationId); + // Obtain the inventory rule. + GetInventoryConfigurationResult result = obsClient.getInventoryConfiguration(request); + InventoryConfiguration inventoryConfiguration = result.getInventoryConfiguration(); + // Print all parameters in the inventory rule. + System.out.println("ConfigurationId:" + inventoryConfiguration.getConfigurationId()); + System.out.println("DestinationBucket:" + inventoryConfiguration.getDestinationBucket()); + System.out.println("InventoryFormat:" + inventoryConfiguration.getInventoryFormat()); + System.out.println("Enabled:" + inventoryConfiguration.getEnabled()); + System.out.println("Frequency:" + inventoryConfiguration.getFrequency()); + System.out.println("IncludedObjectVersions:" + inventoryConfiguration.getIncludedObjectVersions()); + System.out.println("InventoryPrefix:" + inventoryConfiguration.getInventoryPrefix()); + System.out.println("ObjectPrefix:" + inventoryConfiguration.getObjectPrefix()); + System.out.println("OptionalFields:" + inventoryConfiguration.getOptionalFields()); + // Print the HTTP status code. + System.out.println("HTTP Code: " + result.getStatusCode()); + System.out.println("GetInventoryConfiguration succeeded"); + } catch (ObsException e) { + System.out.println("GetInventoryConfiguration failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("GetInventoryConfiguration failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns a list of all inventory rules for the bucket.
+obsClient.listInventoryConfiguration(ListInventoryConfigurationRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
inventoryConfigurations + |
+List<InventoryConfiguration> + |
+Explanation: +All inventory configurations of the bucket. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
configurationId + |
+String + |
+Yes + |
+Explanation: +ID of a bucket inventory rule. +Restrictions: +The rule ID allows letters (a–z, A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). +Value range: +The value can be up to 64 characters long. +Default value: +None + |
+
isEnabled + |
+boolean + |
+Yes + |
+Explanation: +Whether the bucket inventory rule is enabled. +Value range: +true: The rule is enabled, and an inventory file is generated. +false: The rule is disabled. No inventory file is generated. +Default value: +true + |
+
objectPrefix + |
+String + |
+No + |
+Explanation: +Used to filter objects. Only objects with the specified name prefix are included in the inventory. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
frequency + |
+String + |
+Yes + |
+Explanation: +Intervals when inventories are generated. You can set this parameter to Daily or Weekly. An inventory is generated within one hour from when it is configured for the first time. Then it is generated at the specified intervals. +Value range: +Daily: Inventories are generated once a day. +Weekly: Inventories are generated once a week. +Default value: +None + |
+
inventoryFormat + |
+String + |
+Yes + |
+Explanation: +Inventory file format. Only the CSV format is supported. +Value range: +CSV +Default value: +None + |
+
destinationBucket + |
+String + |
+Yes + |
+Explanation: +Name of the bucket for storing inventories. +Restrictions: +
Default value: +None + |
+
inventoryPrefix + |
+String + |
+No + |
+Explanation: +The prefix of the inventory file name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +If you do not specify this parameter, BucketInventory is used as the prefix by default. + |
+
includedObjectVersions + |
+String + |
+Yes + |
+Explanation: +Whether versions of objects are included in an inventory. +Value range: +
Default value: +None + |
+
optionalFields + |
+ArrayList<String> + |
+No + |
+Explanation: +Additional object metadata fields that are contained in an inventory file. +Value range: +Size: Object size. +LastModifiedDate: Last time when the object was modified. +StorageClass: The storage class of the object. +ETag: The ETag value of the object. +IsMultipartUploaded: Whether the object was uploaded in a multipart upload. +ReplicationStatus: The cross-region replication status of the object. +EncryptionStatus: The encryption status of the object. +Default value: +None + |
+
This example lists all inventory files of bucket example-bucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.inventory.InventoryConfiguration; +import com.obs.services.model.inventory.ListInventoryConfigurationRequest; +import com.obs.services.model.inventory.ListInventoryConfigurationResult; +import java.util.List; +public class ListInventoryConfigurations001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the following parameters. + String exampleBucketName = "example-bucket"; + ListInventoryConfigurationRequest request = new ListInventoryConfigurationRequest(exampleBucketName); + // List all inventory rules. + ListInventoryConfigurationResult result = obsClient.listInventoryConfiguration(request); + List<InventoryConfiguration> inventoryConfigurations = result.getInventoryConfigurations(); + //Print all parameters in all inventory rules. + for (InventoryConfiguration inventoryConfiguration : inventoryConfigurations) { + System.out.println("ConfigurationId:" + inventoryConfiguration.getConfigurationId()); + System.out.println("DestinationBucket:" + inventoryConfiguration.getDestinationBucket()); + System.out.println("InventoryFormat:" + inventoryConfiguration.getInventoryFormat()); + System.out.println("Enabled:" + inventoryConfiguration.getEnabled()); + System.out.println("Frequency:" + inventoryConfiguration.getFrequency()); + System.out.println("IncludedObjectVersions:" + inventoryConfiguration.getIncludedObjectVersions()); + System.out.println("InventoryPrefix:" + inventoryConfiguration.getInventoryPrefix()); + System.out.println("ObjectPrefix:" + inventoryConfiguration.getObjectPrefix()); + System.out.println("OptionalFields:" + inventoryConfiguration.getOptionalFields()); + System.out.println("--------------------------------"); + } + // Print the HTTP status code. + System.out.println("HTTP Code: " + result.getStatusCode()); + System.out.println("ListInventoryConfiguration succeeded"); + } catch (ObsException e) { + System.out.println("ListInventoryConfiguration failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("ListInventoryConfiguration failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API deletes an inventory rule (identified by configurationId) from the bucket.
+obsClient.deleteInventoryConfiguration(DeleteInventoryConfigurationRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
configurationId + |
+String + |
+Yes + |
+Explanation: +ID of the inventory rule to be deleted. The ID can be up to 64 bytes long and allows letters (a–z, A–Z), digits (0–9), hyphens (-), underscores (_), and periods (.). +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes the inventory rule whose ID is exampleConfigId001 for bucket example-bucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HeaderResponse; +import com.obs.services.model.inventory.DeleteInventoryConfigurationRequest; +import com.obs.services.model.inventory.GetInventoryConfigurationRequest; +import com.obs.services.model.inventory.GetInventoryConfigurationResult; +import com.obs.services.model.inventory.InventoryConfiguration; +public class DeleteInventoryConfiguration001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the following parameters. + String exampleBucketName = "example-bucket"; + String exampleConfigurationId = "exampleConfigId001"; + DeleteInventoryConfigurationRequest request = + new DeleteInventoryConfigurationRequest(exampleBucketName, exampleConfigurationId); + // Delete the inventory rule. + HeaderResponse result = obsClient.deleteInventoryConfiguration(request); + // Print the HTTP status code. + System.out.println("HTTP Code: " + result.getStatusCode()); + System.out.println("DeleteInventoryConfiguration succeeded"); + } catch (ObsException e) { + System.out.println("DeleteInventoryConfiguration failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("DeleteInventoryConfiguration failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
In OBS, objects are basic data units that users can perform operations on. OBS Java SDK provides abundant APIs for object upload in the following methods:
+ +The SDK supports the upload of objects whose size ranges from 0 KB to 5 GB. For streaming upload, appendable upload, and file-based upload, data to be uploaded cannot be larger than 5 GB. If the file is larger than 5 GB, multipart upload (where each part is smaller than 5 GB) is suitable. Browser-based upload allows files to be uploaded through a browser.
+If you grant anonymous users the read permission for an object during the upload, anonymous users can access the object through a URL after the upload is complete. The object URL is in the format of https://bucket name.domain name/directory level/object name. If the object resides in the root directory of the bucket, its URL does not contain directory levels.
+This API uploads a local file to OBS over the Internet. These files can be texts, images, videos, or any other type of files.
+You can upload texts, images, videos, or any other types of files smaller than 5 GB. In a streaming upload, java.io.InputStream is used as the object data source. You can call ObsClient.putObject to upload data streams to OBS.
+obsClient.putObject(PutObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 4. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +ACL that can be pre-defined when an object is created. Refer to Table 6 to choose the option you need. +Value range: +
Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Information about the server-side encryption header. For details, see Table 14. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Information about the server-side encryption header. For details, see Table 13. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured when uploading an object or using the x-obs-expires header in a metadata API call. +Value range: +An integer greater than 0, in days +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 18. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Size of the object. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +Multipurpose Internet Mail Extensions (MIME) type of the object to be uploaded. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Object storage class that can be specified at object creation. If this parameter is not specified, the object inherits the storage class of the bucket where it is to be uploaded by default. +Value range: +See Table 21. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 11. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 7. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 8. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 12. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 9. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 10. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating Advanced Encryption Standard (AES) is used to encrypt the object in SSE-C. For details, see Table 17. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +AES256 +Value range: +See Table 16. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 15. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 16. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used to obtain the upload progress. For details, see Table 19. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 20. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Object storage class. If the storage class is Standard, leave this parameter blank. +Value range: +See Table 21. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version ID will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
The following code is used to upload the Hello OBS character string to the examplebucket bucket and name it objectname.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import java.io.ByteArrayInputStream; +public class PutObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload a string and convert it to a byte array. + String content = "Hello OBS"; + obsClient.putObject("examplebucket", "objectname", new ByteArrayInputStream(content.getBytes())); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The following code is used to upload the http://www.a.com network stream to the examplebucket bucket and name it objectname.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import java.io.InputStream; +import java.net.URL; +public class PutObject002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload a network stream. + InputStream inputStream = new URL("http://www.a.com").openStream(); + obsClient.putObject("examplebucket", "objectname", inputStream); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The following code is used to upload the localfile file stream to the objectname object in the dir directory of bucketname.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +import java.io.FileInputStream; +public class PutObject003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Path of the local file to be uploaded, in which the file name must be specified. + FileInputStream fis = new FileInputStream(new File("localfile")); + obsClient.putObject("examplebucket", "dir/objectname", fis); + // Path of the local file to be uploaded, in which the file name must be specified. + FileInputStream fis2 = new FileInputStream(new File("localfile2")); + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname2"); + request.setInput(fis2); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API uploads local files to OBS over the Internet. The file to be uploaded can be of any type.
+obsClient.putObject(PutObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 19. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +ACL that can be pre-defined when an object is created. Refer to Table 12 to choose the option you need. +Value range: +
Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 14. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 13. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured when uploading an object or using the x-obs-expires header in a metadata API call. +Value range: +An integer greater than 0, in days +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 3. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 4. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress status. For details, see Obtaining the Upload Progress. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS used for encrypting objects. +Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 10. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 10. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 13. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 14. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 16. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 15. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 17. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 18. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Size of the object. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object to be uploaded. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Object storage class that can be specified at object creation. If this parameter is not specified, the object inherits the storage class of the bucket where it is to be uploaded by default. +Value range: +See Table 20. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 20. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version ID will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
This example uploads local files to bucket examplebucket.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload files. + // localfile indicates the path of the local file to be uploaded, in which the file name must be specified. + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectkey"); + request.setFile(new File("localfile")); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the upload progress of a specified object.
+You can call PutObjectRequest.setProgressListener to obtain the upload progress.
+PutObjectRequest.setProgressListener(ProgressListener progressListener)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
progressListener + |
++ | +Yes + |
+Explanation: +Data transmission listener for obtaining the upload progress. For details, see Table 2. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 4. + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
This example returns the progress of uploading local file exampleLocalFilePath to bucket examplebucket as object objectname.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ProgressListener; +import com.obs.services.model.ProgressStatus; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject005 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload a file. + PutObjectRequest request = new PutObjectRequest("examplebucket", "exampleobject"); + request.setFile(new File("exampleLocalFilePath")); + request.setProgressListener( + new ProgressListener() { + @Override + public void progressChanged(ProgressStatus status) { + // Obtain the average upload rate. + System.out.println("AverageSpeed:" + status.getAverageSpeed()); + // Obtain the upload progress in percentage. + System.out.println("TransferPercentage:" + status.getTransferPercentage()); + } + }); + // Refresh the upload progress each time 1 MB data is uploaded. + request.setProgressInterval(1024 * 1024L); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
import com.obs.services.ObsClient; +import com.obs.services.ObsConfiguration; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.ProgressListener; +import com.obs.services.model.ProgressStatus; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +import java.io.FileInputStream; +public class PutObjectByInputStreamWithProgress { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the bucket. + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + String endPoint = "https://obs.region.example.com"; + ObsConfiguration obsConfiguration = new ObsConfiguration(); + obsConfiguration.setEndPoint(endPoint); + // Create an ObsClient instance. + try (ObsClient obsClient = new ObsClient(ak, sk, securityToken, obsConfiguration)) { + String exampleBucket = "examplebucket"; + String exampleObject = "objectname"; + String fileToUpload = "exampleFileName"; + long contentLength = new File(fileToUpload).length(); + PutObjectRequest request = new PutObjectRequest(exampleBucket, exampleObject, new FileInputStream(fileToUpload)); + ObjectMetadata objectMetadata = new ObjectMetadata(); + // Streaming uploads require the object attribute Content-Length must be configured. + // Otherwise, ProgressStatus.getTransferPercentage () returns -1. + objectMetadata.setContentLength(contentLength); + request.setMetadata(objectMetadata); + request.setProgressListener( + new ProgressListener() { + @Override + public void progressChanged(ProgressStatus status) { + // Obtain the average upload rate. + System.out.println("AverageSpeed:" + status.getAverageSpeed()); + // Obtain the upload progress in percentage. + System.out.println("TransferPercentage:" + status.getTransferPercentage()); + } + }); + // Refresh the upload progress each time 1 MB data is uploaded. + request.setProgressInterval(1024 * 1024L); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +}+
This API creates a folder in an existing bucket to manage data in OBS.
+OBS does not involve folders like in a file system. All elements in buckets are objects. To create a folder in OBS is essentially to create an object whose size is 0 and whose name ends with a slash (/). Such objects are no different from other objects (you can perform normal operations on them such as download and delete), except that they are displayed as folders in OBS console.
+obsClient.putObject(PutObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 14. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +ACL that can be pre-defined when an object is created. Refer to Table 15 to choose the option you need. +Value range: +
Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 14. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 13. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured when uploading an object or using the x-obs-expires header in a metadata API call. +Value range: +An integer greater than 0, in days +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 10. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 12. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 12. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Size of the object. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object to be uploaded. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 13. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 16. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 17. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 19. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 18. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 20. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 21. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 21. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version ID will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
This example uses the object upload operation to create folder parent_directory/ in bucket examplebucket.
+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 +49 +50 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import java.io.ByteArrayInputStream; +public class PutObject006 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Create a folder. + final String keySuffixWithSlash = "parent_directory/"; + obsClient.putObject("examplebucket", keySuffixWithSlash, new ByteArrayInputStream(new byte[0])); + // Create an object in the folder. + obsClient.putObject( + "examplebucket", keySuffixWithSlash + "objectname", new ByteArrayInputStream("Hello OBS".getBytes())); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API configures metadata for an object when uploading it. Object metadata include the object length, MIME type, MD5 value (for verification), storage class, and custom object metadata. You can configure metadata for an object that is being uploaded in streaming, file-based, or multipart mode or when copying an object.
+obsClient.putObject(PutObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 14. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +ACL that can be pre-defined when an object is created. Refer to Table 15 to choose the option you need. +Value range: +
Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 9. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 8. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured when uploading an object or using the x-obs-expires header in a metadata API call. +Value range: +An integer greater than 0, in days. +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 10. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 12. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 12. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the file. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Object storage class that can be specified at object creation. If this parameter is not specified, the object inherits the storage class of the bucket where it is to be uploaded by default. +Value range: +See Table 13. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 16. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 17. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 19. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 18. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 20. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 21. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Object storage class that can be specified at object creation. If this parameter is not specified, the object inherits the storage class of the bucket where it is to be uploaded by default. +Value range: +See Table 13. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version ID will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An uploaded object or copied object has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
This example uploads local file localfile to bucket examplebucket as object objectname and sets its length to 1024 * 1024L.
+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 +49 +50 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import java.io.File; +import java.io.IOException; +public class PutObject007 { + public static void main(String[] args) throws IOException { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the length for an object. + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setContentLength(1024 * 1024L); // 1MB + obsClient.putObject("examplebucket", "objectname", new File("localfile"), metadata); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uploads local file localimage.jpg to bucket examplebucket as object objectname.jpg and sets the MIME type of the object to image/jpeg.
+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 +49 +50 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import java.io.File; +public class PutObject008 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the MIME type for an object. + // Upload an image. + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setContentType("image/jpeg"); + obsClient.putObject("examplebucket", "objectname.jpg", new File("localimage.jpg"), metadata); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uploads local file localimage.jpg to bucket examplebucket as object objectname and calls ObsClient.base64Md5 to calculate the Content-MD5 header.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +public class PutObject009 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the MD5 value for an object. + // Upload an image. + ObjectMetadata metadata = new ObjectMetadata(); + // Your file's Base64-encoded MD5 + String base64Md5 = obsClient.base64Md5(Files.newInputStream(Paths.get("localimage.jpg"))); + metadata.setContentMd5(base64Md5); + obsClient.putObject("examplebucket", "objectname", new File("localimage.jpg"), metadata); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uploads local file localfile to object objectname in bucket examplebucket, customizes two pieces of metadata named property1 and property2, and sets their respective values to property-value1 and property-value2.
+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 +49 +50 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import java.io.File; +public class PutObject011 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set user-defined metadata for the object. + ObjectMetadata metadata = new ObjectMetadata(); + metadata.addUserMetadata("property1", "property-value1"); + metadata.getMetadata().put("property2", "property-value2"); + obsClient.putObject("examplebucket", "objectname", new File("localfile"), metadata); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uploads local file localfile to bucket exampleBucket as object objectname and sets the object storage class to Warm.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.StorageClassEnum; +import java.io.File; +public class PutObject010 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the storage class for an object. + ObjectMetadata metadata = new ObjectMetadata(); + // Set the storage class of the object to Warm. + metadata.setObjectStorageClass(StorageClassEnum.WARM); + obsClient.putObject("examplebucket", "objectname", new File("localfile"), metadata); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can configure lifecycle rules to periodically delete objects or transition objects between storage classes. The object expiration time set using this API takes precedence over that set in a bucket lifecycle rule.
+You can also set the object expiration time when uploading an object or initiating a multipart upload.
+
obsClient.putObject(PutObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 14. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 9. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 8. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +
Value range: +An integer greater than 0, in days. +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 10. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 12. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for server-side encryption. Objects are encrypted using SSE-KMS on the server side. +Value range: +kms. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 12. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the file. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 13. +Restrictions: +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 16. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 17. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 19. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 18. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 20. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 21. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. +Value range: +See Table 13. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version ID will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An uploaded object or copied object has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
This example uploads localfile to object objectname in bucket examplebucket and sets the object expiration time to 30 days.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject012 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setFile(new File("localfile")); + // When uploading an object, set the object to expire after 30 days. + request.setExpires(30); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
obsClient.appendObject(AppendObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for an append upload. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 14. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 9. +Restrictions: +If you use SSE-KMS encryption, the encryption header you configure, such as x-obs-server-side-encryption, only needs to be carried when the object is uploaded for the first time and no object with the same name exists in the bucket. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 8. +Restrictions: +If you use SSE-C encryption, the encryption header you configure, such as x-obs-server-side-encryption, must be carried in each append upload. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured when uploading an object or using the x-obs-expires header in a metadata API call. +Value range: +An integer greater than 0, in days. +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 4. + |
+
position + |
+long + |
+Yes + |
+Explanation: +Position where the object data is appended. +Restrictions: +For an object to be appended, the value of position must be set to 0 when the object is uploaded for the first time. The value of position will be carried in the x-obs-next-append-position header of the response returned by the server when the object is successfully uploaded next time. +Default value: +None + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 10. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 12. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for server-side encryption. Objects are encrypted using SSE-KMS on the server side. +Value range: +kms. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 12. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the file. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 13. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 16. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 17. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 19. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 18. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Description + |
+
|---|---|
| + | +Explanation: +Grantee (user) information. For details, see Table 20. + |
+
| + | +Explanation: +Grantee (user group) information. +Value range: +See Table 21. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
etag + |
+String + |
+Explanation: +Base64-encoded, 128-bit MD5 value of the appended content. The ETag returned for the append upload is the ETag for the appended content, not that for the entire object. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An uploaded object or copied object has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 13. +Default value: +None + |
+
nextPosition + |
+long + |
+Explanation: +Position from which the next append upload starts +Default value: +None + |
+
This example appends data to object objectname in bucket examplebucket by specifying an append position.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AppendObjectRequest; +import com.obs.services.model.AppendObjectResult; +import com.obs.services.model.ObjectMetadata; +import java.io.ByteArrayInputStream; +public class AppendObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try (ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint)) { + // Append data for the first time. + AppendObjectRequest request = new AppendObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setPosition(0); + request.setInput(new ByteArrayInputStream("Hello OBS".getBytes())); + AppendObjectResult result = obsClient.appendObject(request); + // Append data for the second time. + request.setPosition(result.getNextPosition()); + request.setInput(new ByteArrayInputStream("Hello OBS Again".getBytes())); + result = obsClient.appendObject(request); + System.out.println("appendObject successfully"); + System.out.println("NextPosition:" + result.getNextPosition()); + System.out.println("Etag:" + result.getEtag()); + // Use the API for obtaining object metadata to get the start position for the next append. + ObjectMetadata metadata = obsClient.getObjectMetadata("examplebucket", "objectname"); + System.out.println("NextPosition from metadata:" + metadata.getNextPosition()); + } catch (ObsException e) { + System.out.println("appendObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("appendObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The resumable upload is an encapsulated and enhanced version of the multipart upload used for dealing with possible upload failures of large files when the network connection is unstable or a program crashes. This API splits the file into multiple parts and uploads them individually. The upload result of each part is recorded in a checkpoint file in real time. A success message is returned only when all parts are uploaded. If any parts fail, an error message is returned telling you to call the API again to upload the failed parts. Since the checkpoint file contains the progress of each part, it saves you uploading all parts again in the event of an error.
+obsClient.uploadFile(UploadFileRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
objectMetadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 14. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 9. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 8. +Default value: +None + |
+
enableCheckpoint + |
+boolean + |
+No + |
+Explanation: +Whether to enable the resumable mode. +Value range: +true: The resumable mode is enabled. +false: The resumable mode is disabled. +Default value: +false + |
+
checkpointFile + |
+String + |
+No + |
+Explanation: +Path of a file generated for recording the progress of a resumable upload. The file contains the information about parts and the upload progress. +Restrictions: +This parameter is valid only for resumable uploads. +Default value: +If this parameter is left blank, the progress file will be in the same directory as the local file to be uploaded. + |
+
uploadFile + |
+String + |
+Yes + |
+Explanation: +Full path of the file or folder to be uploaded, for example, aa/bb.txt or aa/. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener, used for obtaining the upload progress. For details, see Table 4. + |
+
partSize + |
+long + |
+No + |
+Explanation: +Part size. +Value range: +The value ranges from 100 KB to 5 GB, in bytes. +Default value: +9 MB + |
+
taskNum + |
+int + |
+No + |
+Explanation: +Maximum number of files that can be uploaded concurrently in a multipart upload. +Value range: +An integer from 1 to 10000 +Default value: +1, indicating concurrent uploads are not used. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 10. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 12. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 12. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 13. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 16. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 17. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 19. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 18. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Description + |
+
|---|---|
| + | +Explanation: +Grantee (user) information. For details, see Table 20. + |
+
| + | +Explanation: +Grantee (user group) information. +Value range: +See Table 21. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version number will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
This example uses the resumable method to upload localfile to bucket examplebucket as object objectKey.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CompleteMultipartUploadResult; +import com.obs.services.model.UploadFileRequest; +public class UploadFile001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + UploadFileRequest request = new UploadFileRequest("examplebucket", "objectKey"); + // Configure the local file to be uploaded. localfile is the path of the file to be uploaded. You must specify a file name with the extension. + request.setUploadFile("localfile"); + // Set the maximum number of parts that can be concurrently uploaded. + request.setTaskNum(5); + // Set the part size to 10 MB. + request.setPartSize(10 * 1024 * 1024); + // Enable the resumable upload. + request.setEnableCheckpoint(true); + // Perform a resumable upload. + CompleteMultipartUploadResult result = obsClient.uploadFile(request); + System.out.println("UploadFile successfully"); + } catch (ObsException e) { + // If there is an exception, you can call the API again to resume the upload. + System.out.println("UploadFile failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("UploadFile failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API uploads an object up to 5 GB to a specified bucket in HTML form.
+You can call ObsClient.createPostSignature to generate request parameters for a browser-based upload. The procedure is as follows:
+
There are two request parameters generated for authentication:
+obsClient.createPostSignature(PostSignatureRequest request)
+ +Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for a browser-based upload. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+No + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+No + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
requestDate + |
+Date + |
+No + |
+Explanation: +Time the request is initiated. +Default value: +None + |
+
expiryDate + |
+Date + |
+No + |
+Explanation: +Date of expiry. +Default value: +None + |
+
expires + |
+long + |
+No + |
+Explanation: +Validity period of authentication for a browser-based upload +Value range: +An integer greater than 0, in seconds. +Default value: +300 + |
+
conditions + |
+List<String> + |
+No + |
+Explanation: +The conditions specified for the form. The SDK uses the specified value to calculate the policy and ignores the formParams. +Default value: +None + |
+
formParams + |
+Map<String, Object> + |
+No + |
+Explanation: +Form parameters in the request. String indicates the name of the form parameter, and Object indicates the value of the form parameter. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
OriginPolicy + |
+String + |
+Explanation: +Value of Policy that is not encoded by Base64. This parameter can only be used for verification. For example: +{"expiration":"2023-09-12T12:52:59Z","conditions":[{"content-type":"text/plain"},{"bucket":"examplebucket"},{"key":"example/objectname"},]}" +Default value: +None + |
+
Policy + |
+String + |
+Explanation: +Base64-encoded value of the policy. For example: +eyJleHBpcmF0aW9uIjoiMjAyMy0wOS0xMlQxMjo1Mjo1OVoiLCJjb25kaXRpb25zIjpbeyJjb250ZW50LXR5cGUiOiJ0ZXh0L3BsYWluIn0seyJidWNrZXQiOiJleGFtcGxlYnVja2V0In0seyJrZXkiOiJleGFtcGxlL29iamVjdG5hbWUifSxdfQ== +Default value: +None + |
+
Signature + |
+String + |
+Explanation: +signature in the form. For example: +g0jQr4v9VWd1Q2FOFDG6LGfV9Cw= +Default value: +None + |
+
This example generates authorization parameters for a browser-based upload.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PostSignatureRequest; +import com.obs.services.model.PostSignatureResponse; +import java.util.HashMap; +import java.util.Map; +public class PostObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Generate a request for a browser-based upload. + PostSignatureRequest request = new PostSignatureRequest(); + // Set form parameters. + Map<String, Object> formParams = new HashMap<String, Object>(); + // Set the object ACL to public read. + formParams.put("x-obs-acl", "public-read"); + // Set the MIME type for an object. + formParams.put("content-type", "text/plain"); + request.setFormParams(formParams); + // Set the validity period for the browser-based upload request, in seconds. + request.setExpires(3600); + PostSignatureResponse response = obsClient.createPostSignature(request); + System.out.println("createPostSignature successfully"); + // Obtain the request parameters. + System.out.println("Policy:" + response.getPolicy()); + System.out.println("Signature:" + response.getSignature()); + } catch (ObsException e) { + System.out.println("createPostSignature failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("createPostSignature failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example is an HTML form.
+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 | <html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +</head> +<body> +<form action="http://bucketname.your-endpoint/" method="post" enctype="multipart/form-data"> + Object key + <!-- Object name --> + <input type="text" name="key" value="objectname" /> + <p> + ACL + <!-- Object ACL --> + <input type="text" name="x-obs-acl" value="public-read" /> + <p> + Content-Type + <!-- Object MIME type --> + <input type="text" name="content-type" value="text/plain" /> + <p> + <!-- Use the value returned by PostSignatureResponse.getPolicy(). --> + <input type="hidden" name="policy" value="*** Provide your policy ***" /> + <!-- AK --> + <input type="hidden" name="AccessKeyId" value="*** Provide your access key ***"/> + <!-- Signature string --> + <input type="hidden" name="signature" value="*** Provide your signature ***"/> + <!-- If x-obs-security-token exists, remove the comment for the following line and specify the actual value of x-obs-security-token. --> + <!-- <input type="hidden" name="x-obs-security-token" value="*** Provide your x-obs-security-token ***"/>--> + <input name="file" type="file" /> + <input name="submit" value="Upload" type="submit" /> +</form> +</body> +</html> + |
You can upload large files using multipart upload. Multipart upload is applicable to many scenarios, including:
+A multipart upload has the following advantages:
+A multipart upload consists of the following steps:
+This API initiates a multipart upload and returns a globally unique upload ID. You can use this upload ID in your subsequent requests including abortMultipartUpload, listMultipartUploads, and listParts.
+obsClient.initiateMultipartUpload(InitiateMultipartUploadRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for initiating a multipart upload. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 11. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL that can be specified at bucket creation. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 6. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 5. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured when uploading an object or using the x-obs-expires header in a metadata API call after the object has been uploaded. +Value range: +An integer greater than 0, in days. +Default value: +None + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 7. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 9. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in bytes. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for server-side encryption. Objects are encrypted using SSE-KMS on the server side. +Value range: +kms. For details, see Table 8. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 9. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the file. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 10. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 13. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 14. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 16. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 15. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 17. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 18. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
uploadId + |
+String + |
+Explanation: +The ID created by the OBS server to identify the multipart upload globally. +Value range: +The value must contain 1 to 32 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Name of the bucket involved in the multipart upload. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Name of the object to be uploaded. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
This example initiates a multipart upload for object objectname in bucket examplebucket and obtains the upload ID.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.InitiateMultipartUploadRequest; +import com.obs.services.model.InitiateMultipartUploadResult; +import com.obs.services.model.ObjectMetadata; +public class InitiateMultipartUpload001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest("examplebucket", "objectname"); + ObjectMetadata metadata = new ObjectMetadata(); + metadata.addUserMetadata("property", "property-value"); + metadata.setContentType("text/plain"); + request.setMetadata(metadata); + InitiateMultipartUploadResult result = obsClient.initiateMultipartUpload(request); + String uploadId = result.getUploadId(); + System.out.println("initiateMultipartUpload successfully"); + System.out.println("uploadId:" + uploadId); + } catch (ObsException e) { + System.out.println("initiateMultipartUpload failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("initiateMultipartUpload failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
After a multipart upload is initiated, this API uploads a part to a specified bucket. In the upload request, the multipart upload ID must be included. Except for the part lastly being uploaded whose size ranges from 0 to 5 GB, sizes of the other parts range from 100 KB to 5 GB. Part numbers can be any number from 1 to 10,000.
+When uploading a part, you must specify its upload ID and part number. A part number uniquely identifies a part and its position in the object you are uploading. If you upload a new part with the same part number as that of a previous part, the previously uploaded part will be overwritten. Whenever you upload a part, OBS returns the ETag header in the response. For each part upload task, you must record the part number and ETag value. These values are required in subsequent requests for you to complete a multipart upload.
+obsClient.uploadPart(UploadPartRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading a part. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
partNumber + |
+int + |
+Yes + |
+Explanation: +Part number. +Value range: +The value ranges from 1 to 10000. If a part number is not within the range, OBS returns error code 400 Bad Request. +Default value: +None + |
+
uploadId + |
+String + |
+Yes + |
+Explanation: +Multipart upload ID, which can be returned by initiating a multipart upload, for example, 000001648453845DBB78F2340DD460D8. +Restrictions: +The value must contain 32 characters. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Restrictions: +You must specify either file or input. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Restrictions: +You must specify either file or input. If one of the two parameters is left blank, the other must be specified. +Default value: +None + |
+
offset + |
+long + |
+No + |
+Explanation: +Start offset of a part in the source file. This parameter is not supported for streams. +Value range: +A non-negative integer not exceeding the size of the object to be uploaded, in bytes. +Default value: +0 + |
+
partSize + |
+Long + |
+No + |
+Explanation: +Part size. +Restrictions: +
Value range: +The value ranges from 100 KB to 5 GB, in bytes. +Default value: +102400 + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 3. +Default value: +None + |
+
attachMd5 + |
+boolean + |
+No + |
+Explanation: +Whether to automatically calculate the MD5 value of the data to be uploaded. To ensure data integrity, set UploadPartRequest.setAttachMd5 to true to make the SDK automatically calculate the MD5 value (valid only when the data source is a local file) of each part and add the MD5 value to the Content-MD5 request header. The OBS server will calculate the MD5 value of the uploaded data and compare it with the MD5 value calculated by the SDK. +Restrictions: +If attachMd5 and contentMd5 are used at the same time, attachMd5 is ignored. +Value range: +true: The MD5 value of the data to be uploaded is automatically calculated. +false: The MD5 value of the data to be uploaded is not automatically calculated. +Default value: +false + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the part to be uploaded, which uniquely identifies the content of the uploaded part and can be used to identify whether the object content is changed. +Restrictions: +If attachMd5 and contentMd5 are used at the same time, attachMd5 is ignored. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 7. + |
+
progressInterval + |
+long + |
+No + |
+Explanation: +Interval for reporting the upload progress, in bytes. For example, 1024 * 1024L indicates that the upload progress is reported each time 1 MB data is uploaded. +Default value: +100 * 1024L + |
+
autoClose + |
+boolean + |
+No + |
+Explanation: +Whether to automatically close data streams after the upload is complete. +Value range: +true: The data stream is automatically closed. +false: The data stream is not automatically closed. +Default value: +true + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 4. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 5. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the upload progress. For details, see Table 8. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 9. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
partNumber + |
+int + |
+Explanation: +Part number. +Value range: +[1,10000] +Default value: +None + |
+
etag + |
+String + |
+Explanation: +Base64-encoded, 128-bit MD5 value of a part. ETag is the unique identifier of the part contents and is used to determine whether the contents of a part are changed. For example, if the ETag value is A when a part is uploaded and is B when the part is downloaded, this indicates the contents of the part are changed. The ETag reflects changes only to the contents of a part, not its metadata. Parts created by the upload and copy operations have unique ETags after being encrypted using MD5. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
This example calls obsClient.uploadPart to upload parts to object objectname in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PartEtag; +import com.obs.services.model.UploadPartRequest; +import com.obs.services.model.UploadPartResult; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +public class UploadPart001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + String uploadId = "upload id from initiateMultipartUpload"; + List<PartEtag> partEtags = new ArrayList<PartEtag>(); + // Upload the first part. + UploadPartRequest request = new UploadPartRequest("examplebucket", "objectname"); + // Set the upload ID. + request.setUploadId(uploadId); + // Set the part number, which ranges from 1 to 10000. + request.setPartNumber(1); + // Specify the large file to be uploaded. + request.setFile(new File("localfile")); + // Set the part size. + request.setPartSize(5 * 1024 * 1024L); + UploadPartResult result = obsClient.uploadPart(request); + partEtags.add(new PartEtag(result.getEtag(), result.getPartNumber())); + // Upload the second part. + request = new UploadPartRequest("examplebucket", "objectname"); + // Set the upload ID. + request.setUploadId(uploadId); + // Set the part number. + request.setPartNumber(2); + // Specify the large file to be uploaded. + request.setFile(new File("localfile")); + // Set the offset of the second part. This parameter takes effect only when a file is uploaded. This parameter is not supported for streams. + request.setOffset(5 * 1024 * 1024L); + // Set the part size. + request.setPartSize(5 * 1024 * 1024L); + result = obsClient.uploadPart(request); + partEtags.add(new PartEtag(result.getEtag(), result.getPartNumber())); + System.out.println("uploadPart successfully"); + } catch (ObsException e) { + System.out.println("uploadPart failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("uploadPart failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API assembles the uploaded parts to complete the multipart upload. Before performing this operation, you cannot download the uploaded data. When assembling parts, you need to copy the additional message header information recorded during the multipart upload initiation to the object metadata. Such information is processed the same way the information in a common object upload is processed. In the case of assembling parts concurrently, last write wins is applied, but the time of last write is defined as the time when a multipart upload was initiated.
+As long as the multipart upload is not aborted, all uploaded parts occupy the space. However, after you assembled the specified parts, those uploaded but not assembled will be deleted to free up space.
+When assembling parts, OBS creates an object by putting part numbers in ascending order. If any object metadata is provided in the initiation of the multipart upload, OBS will associate the metadata with the object. After the multipart upload is complete, the parts will no longer exist. A part assembling request must contain the upload ID, part numbers, and a list of corresponding ETag values. In response to the request, the ETag that uniquely identifies the assembled parts is contained. This ETag is not the MD5 hash value of the entire object.
+obsClient.completeMultipartUpload(CompleteMultipartUploadRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for assembling parts. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
partEtag + |
+List<PartEtag> + |
+Yes + |
+Explanation: +List of parts to be assembled. For details, see Table 3. + |
+
uploadId + |
+String + |
+Yes + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
encodingType + |
+String + |
+No + |
+Explanation: +Encoding type for objectKey in the response. If objectKey in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode objectKey. +Value range: +url +Default value: +None. If you leave this parameter blank, encoding is not applied. + |
+
userHeaders + |
+HashMap<String, String> + |
+No + |
+Explanation: +User header list. In HashMap, the String key and value indicate the name and value of the user header field respectively. The SDK does not process the userHeaders and instead transparently transmits it to the server for later use. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
etag + |
+String + |
+Yes + |
+Explanation: +Part ETag. Base64-encoded, 128-bit MD5 value of the part. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
partNumber + |
+Integer + |
+Yes + |
+Explanation: +Part number. Part numbers can be inconsecutive. +Value range: +An integer ranging from 1 to 10000. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket in which parts are assembled. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +The name of the object the parts are assembled into. +An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
location + |
+String + |
+Explanation: +URL of the object the parts are assembled into. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Version ID of the object the parts are assembled into. If versioning is enabled for the bucket, the object version number will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectUrl + |
+String + |
+Explanation: +Full path to the object the parts are assembled into. +Default value: +None + |
+
encodingType + |
+String + |
+Explanation: +Encoding type for objectKey in the response. If objectKey in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode objectKey. +Value range: +url +Default value: +None. If you leave this parameter blank, encoding is not applied. + |
+
This example calls ObsClient.completeMultipartUpload to assemble parts into object objectname in bucket examplebucket based on uploadId and partEtags.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CompleteMultipartUploadRequest; +import com.obs.services.model.PartEtag; +import java.util.ArrayList; +import java.util.List; +public class CompleteMultipartUpload001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + String uploadId = "upload id from initiateMultipartUpload"; + List<PartEtag> partEtags = new ArrayList<PartEtag>(); + // First part + PartEtag part1 = new PartEtag(); + part1.setPartNumber(1); + part1.seteTag("etag1"); + partEtags.add(part1); + // Second part + PartEtag part2 = new PartEtag(); + part2.setPartNumber(2); + part2.setEtag("etag2"); + partEtags.add(part2); + CompleteMultipartUploadRequest request = + new CompleteMultipartUploadRequest("examplebucket", "objectname", uploadId, partEtags); + obsClient.completeMultipartUpload(request); + System.out.println("completeMultipartUpload successfully"); + } catch (ObsException e) { + System.out.println("CompleteMultipartUpload failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("completeMultipartUpload failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Multipart upload is mainly used for large file upload or when the network connection is poor.
+You can use UploadPartRequest.setOffset and UploadPartRequest.setPartSize to set the start and end positions for uploading a part.
+This example uploads a large file by concurrently uploading parts.
+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 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CompleteMultipartUploadRequest; +import com.obs.services.model.InitiateMultipartUploadRequest; +import com.obs.services.model.InitiateMultipartUploadResult; +import com.obs.services.model.PartEtag; +import com.obs.services.model.UploadPartRequest; +import com.obs.services.model.UploadPartResult; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +public class ConcurrentUploadPart001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + final String bucketName = "examplebucket"; + final String objectKey = "objectname"; + // Initialize the thread pool. + ExecutorService executorService = Executors.newFixedThreadPool(20); + final File largeFile = new File("localfile"); + // Initiate a multipart upload. + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, objectKey); + InitiateMultipartUploadResult result = obsClient.initiateMultipartUpload(request); + final String uploadId = result.getUploadId(); + System.out.println("\t" + uploadId + "\n"); + // Set the part size to 100 MB. + long partSize = 100 * 1024 * 1024L; + long fileSize = largeFile.length(); + // Calculate the number of parts to be uploaded. + long partCount = fileSize % partSize == 0 ? fileSize / partSize : fileSize / partSize + 1; + final List<PartEtag> partEtags = Collections.synchronizedList(new ArrayList<PartEtag>()); + // Start uploading parts concurrently. + for (int i = 0; i < partCount; i++) { + // Set the start position of a part in the file. + final long offset = i * partSize; + // Set the part size. + final long currPartSize = (i + 1 == partCount) ? fileSize - offset : partSize; + // Set the part number. + final int partNumber = i + 1; + executorService.execute( + new Runnable() { + @Override + public void run() { + UploadPartRequest uploadPartRequest = new UploadPartRequest(); + uploadPartRequest.setBucketName(bucketName); + uploadPartRequest.setObjectKey(objectKey); + uploadPartRequest.setUploadId(uploadId); + uploadPartRequest.setFile(largeFile); + uploadPartRequest.setPartSize(currPartSize); + uploadPartRequest.setOffset(offset); + uploadPartRequest.setPartNumber(partNumber); + UploadPartResult uploadPartResult; + try { + uploadPartResult = obsClient.uploadPart(uploadPartRequest); + System.out.println("Part#" + partNumber + " done\n"); + partEtags.add( + new PartEtag(uploadPartResult.getEtag(), uploadPartResult.getPartNumber())); + } catch (ObsException e) { + e.printStackTrace(); + } + } + }); + } + // Wait until the upload is complete. + executorService.shutdown(); + while (!executorService.isTerminated()) { + try { + executorService.awaitTermination(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // Assemble parts. + CompleteMultipartUploadRequest completeMultipartUploadRequest = + new CompleteMultipartUploadRequest(bucketName, objectKey, uploadId, partEtags); + obsClient.completeMultipartUpload(completeMultipartUploadRequest); + System.out.println("completeMultipartUpload successfully"); + } catch (ObsException e) { + System.out.println("CompleteMultipartUpload failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("completeMultipartUpload failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API aborts a multipart upload using the multipart upload ID.
+After a multipart upload is aborted, the upload ID cannot be used to upload any part. The storage occupied by any uploaded parts will be released. If any part uploads are in progress, aborting the multipart upload might or might not make the uploads successful. To release the storage occupied by all uploaded parts, you can only abort the multipart upload after all parts have been uploaded.
+obsClient.abortMultipartUpload(AbortMultipartUploadRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for aborting a multipart upload. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Bucket name. +Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
uploadId + |
+String + |
+Yes + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example calls ObsClient.abortMultipartUpload to abort the multipart upload of object objectname in bucket examplebucket based on the upload ID obtained during the multipart upload initiation.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AbortMultipartUploadRequest; +public class AbortMultipartUpload001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + String uploadId = "upload id from initiateMultipartUpload"; + // Abort the multipart upload request. + AbortMultipartUploadRequest request = new AbortMultipartUploadRequest("examplebucket", "objectname", uploadId); + // Abort the multipart upload API. + obsClient.abortMultipartUpload(request); + System.out.println("AbortMultipartUpload successfully"); + } catch (ObsException e) { + System.out.println("AbortMultipartUpload failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("AbortMultipartUpload failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API lists the uploaded parts in a specified bucket. This request must contain the multipart upload ID.
+You can list the uploaded parts of a specified multipart upload or of all ongoing multipart uploads. A maximum of 1,000 uploaded parts can be returned in a response. If your multipart upload has more than 1,000 parts, you need to send multiple requests to list all uploaded parts. Assembled parts will not be listed.
+obsClient.listParts(ListPartsRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for listing uploaded parts. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
uploadId + |
+String + |
+Yes + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. +Value range: +The value must contain 1 to 32 characters. +Default value: +None + |
+
maxParts + |
+Integer + |
+No + |
+Explanation: +Maximum number of parts that can be listed per page. +Restrictions: +If the specified value is greater than 1000, only 1,000 parts are returned. +Value range: +The value ranges from 1 to 1000. +Default value: +1000 + |
+
partNumberMarker + |
+Integer + |
+No + |
+Explanation: +Part number the listing starts from. +Restrictions: +OBS lists only parts with greater numbers than that specified by this parameter. +Default value: +None + |
+
encodingType + |
+String + |
+No + |
+Explanation: +Encoding type for key in the response. If key in the response contains control characters that are not supported by the XML 1.0 standard, you can specify this parameter to encode key. +Value range: +url +Default value: +None. If you leave this parameter blank, encoding is not applied. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
bucket + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
key + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
uploadId + |
+String + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
initiator + |
++ | +Explanation: +Initiator of the multipart upload. For details, see Table 6. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the multipart upload, which is consistent with initiator. For details, see Table 6. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of the object to be uploaded. +Value range: +See Table 5. +Default value: +None + |
+
multipartList + |
+List<Multipart> + |
+Explanation: +List of uploaded parts. For details, see Table 4. +Default value: +None + |
+
maxParts + |
+Integer + |
+Explanation: +Maximum number of parts that can be listed per page, which is consistent with that set in the request. +Restrictions: +If the specified value is greater than 1000, only 1,000 parts are returned. +Value range: +The value ranges from 1 to 1000. +Default value: +1000 + |
+
isTruncated + |
+boolean + |
+Explanation: +Whether all parts are returned in the response. +Value range: +
Default value: +None + |
+
partNumberMarker + |
+String + |
+Explanation: +Part number after which part listing begins, which is consistent with that set in the request. +Default value: +None + |
+
nextPartNumberMarker + |
+String + |
+Explanation: +Part number to start with for the next part listing request. If only part of the uploaded parts are returned for the current request, this parameter is included in the response for setting partNumberMarker in the subsequent request. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
partNumber + |
+Integer + |
+Explanation: +Part number. +Value range: +An integer ranging from 1 to 10000. +Default value: +None + |
+
lastModified + |
+Date + |
+Explanation: +Last time the part was uploaded. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +Part ETag. Base64-encoded, 128-bit MD5 value of the part. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
size + |
+Long + |
+Explanation: +Part size. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
This example lists up to 1,000 parts uploaded to object objectname in bucket examplebucket based on the upload ID obtained through initiateMultipartUpload.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListPartsRequest; +import com.obs.services.model.ListPartsResult; +import com.obs.services.model.Multipart; +public class ListParts001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + String uploadId = "upload id from initiateMultipartUpload"; + // List uploaded parts. uploadId is obtained from the initiateMultipartUpload API. + ListPartsRequest request = new ListPartsRequest("examplebucket", "objectname"); + request.setUploadId(uploadId); + ListPartsResult result = obsClient.listParts(request); + for (Multipart part : result.getMultipartList()) { + // Part number, specified during the upload + System.out.println("PartNumber:" + part.getPartNumber()); + // Part size + System.out.println("Size:" + part.getSize()); + // Part ETag + System.out.println("Etag:" + part.getEtag()); + // Time when the part was last uploaded + System.out.println("LastModified:" + part.getLastModified()); + } + System.out.println("listParts successfully"); + } catch (ObsException e) { + System.out.println("listParts failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listParts failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists over 1,000 parts using pagination.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListPartsRequest; +import com.obs.services.model.ListPartsResult; +import com.obs.services.model.Multipart; +public class ListParts002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + String uploadId = "upload id from initiateMultipartUpload"; + // List uploaded parts. uploadId is obtained from the initiateMultipartUpload API. + ListPartsRequest request = new ListPartsRequest("examplebucket", "objectname"); + request.setUploadId(uploadId); + ListPartsResult result; + do { + result = obsClient.listParts(request); + for (Multipart part : result.getMultipartList()) { + // Part number, specified during the upload + System.out.println("PartNumber:" + part.getPartNumber()); + // Part size + System.out.println("Size:" + part.getSize()); + // Part ETag + System.out.println("Etag:" + part.getEtag()); + // Time when the part was last uploaded + System.out.println("LastModified:" + part.getLastModified()); + } + request.setPartNumberMarker(Integer.parseInt(result.getNextPartNumberMarker())); + } while (result.isTruncated()); + System.out.println("listParts successfully"); + } catch (ObsException e) { + System.out.println("listParts failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listParts failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API lists ongoing multipart uploads.
+Ongoing multipart uploads are the multipart uploads that have been initiated but have not been completed or aborted. A maximum of 1,000 multipart uploads can be returned in a response. If there are over 1,000 ongoing tasks satisfying the list criteria, you need to send more requests to query additional multipart uploads.
+obsClient.listMultipartUploads(ListMultipartUploadsRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for listing multipart uploads. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
prefix + |
+String + |
+No + |
+Explanation: +Prefix that the object names in the multipart uploads to be listed must contain. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, the multipart uploads of logs/day1, logs/day2, and logs/day3 will be returned. If you leave this parameter blank, all multipart uploads in the bucket will be returned. +Restrictions: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
delimiter + |
+String + |
+No + |
+Explanation: +Object names are grouped by this parameter, which is often used with prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one commonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one commonPrefixes. +Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix, and bbcde is grouped separately into another commonPrefixes with bbcd as the prefix. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
maxUploads + |
+Integer + |
+No + |
+Explanation: +Maximum number of multipart uploads to list. +Restrictions: +If the specified value is greater than 1000, only 1,000 multipart uploads are returned. +Value range: +An integer from 1 to 1000 +Default value: +1000 + |
+
keyMarker + |
+String + |
+No + |
+Explanation: +Object name after which the multipart upload listing begins. +Value range: +The value of nextKeyMarker in the response body of the last request. +Default value: +None + |
+
uploadIdMarker + |
+String + |
+No + |
+Explanation: +Upload ID after which the multipart upload listing begins. +Restrictions: +This parameter must be used together with keyMarker, indicating multipart uploads with IDs greater than the specified uploadIdMarker for the specified keyMarker are listed. +Value range: +The value of nextUploadIdMarker in the response body of the last request. +Default value: +None + |
+
encodingType + |
+String + |
+No + |
+Explanation: +Encoding type for some elements in the response. If delimiter, keyMarker, prefix, nextKeyMarker, and objectKey contain control characters that are not supported by the XML 1.0 standard, you can set encodingType to encode delimiter, keyMarker, prefix (including the prefix in commonPrefixes), nextKeyMarker, and objectKey in the response. +Value range: +url +Default value: +None. If you leave this parameter blank, encoding is not applied. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
bucket + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
keyMarker + |
+String + |
+Explanation: +Object name after which the multipart upload listing begins, which is consistent with that set in the request. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
uploadIdMarker + |
+String + |
+Explanation: +Upload ID after which the multipart upload listing begins, which is consistent with that set in the request. +Value range: +The value must contain 1 to 32 characters. +Default value: +None + |
+
nextKeyMarker + |
+String + |
+Explanation: +Object name to start with for the next multipart upload listing request. If only part of multipart uploads are returned for the current request, this parameter is included in the response for setting keyMarker in the subsequent request. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
nextUploadIdMarker + |
+String + |
+Explanation: +Upload ID to start with for the next multipart upload listing request. It is used with the nextKeyMarker parameter. If only part of multipart uploads are returned for the current request, this parameter is included in the response for setting uploadIdMarker in the subsequent request. +Value range: +The value must contain 1 to 32 characters. +Default value: +None + |
+
prefix + |
+String + |
+Explanation: +Object name prefix in multipart uploads, which is consistent with that set in the request. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, the multipart uploads of logs/day1, logs/day2, and logs/day3 will be returned. If you leave this parameter blank, all multipart uploads in the bucket will be returned. +Restrictions: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
maxUploads + |
+int + |
+Explanation: +Maximum number of listed multipart uploads, which is consistent with that set in the request. +Restrictions: +If the specified value is greater than 1000, only 1,000 multipart uploads are returned. +Value range: +An integer from 1 to 1000 +Default value: +1000 + |
+
truncated + |
+boolean + |
+Explanation: +Whether all multipart uploads are returned in the response. +Value range: +
Default value: +None + |
+
multipartTaskList + |
+List<MultipartUpload> + |
+Explanation: +List of multipart uploads. For details, see Table 4. + |
+
delimiter + |
+String + |
+Explanation: +A character used to group object names in multipart uploads, which is consistent with that set in the request. This parameter is often used with prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one commonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one commonPrefixes. +Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefixes with abcd as the prefix, and bbcde is grouped separately into another commonPrefixes with bbcd as the prefix. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
commonPrefixes + |
+String[] + |
+Explanation: +List of object name prefixes grouped according to the delimiter parameter (if specified). +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
uploadId + |
+String + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. +Value range: +The value must contain 1 to 32 characters. +Default value: +None + |
+
initiatedDate + |
+java.util.Date + |
+Explanation: +Time when the multipart upload is initiated. +Restrictions: +The time must be in the ISO8601 format. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of the object to be uploaded. +Value range: +See Table 5. +Default value: +None + |
+
initiator + |
++ | +Explanation: +Initiator of the multipart upload. For details, see Table 6. + |
+
owner + |
++ | +Explanation: +Owner of the multipart upload, which is consistent with initiator. For details, see Table 6. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
This example lists up to 1,000 multipart uploads of bucket examplebucket.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListMultipartUploadsRequest; +import com.obs.services.model.MultipartUpload; +import com.obs.services.model.MultipartUploadListing; +public class ListMultipartUploads001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + ListMultipartUploadsRequest request = new ListMultipartUploadsRequest("examplebucket"); + MultipartUploadListing result = obsClient.listMultipartUploads(request); + for (MultipartUpload upload : result.getMultipartTaskList()) { + System.out.println("UploadId:" + upload.getUploadId()); + System.out.println("ObjectKey:" + upload.getObjectKey()); + System.out.println("InitiatedDate:" + upload.getInitiatedDate()); + } + System.out.println("ListMultipartUploads successfully"); + } catch (ObsException e) { + System.out.println("ListMultipartUploads failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("ListMultipartUploads failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists over 1,000 multipart uploads using pagination.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListMultipartUploadsRequest; +import com.obs.services.model.MultipartUpload; +import com.obs.services.model.MultipartUploadListing; +public class ListMultipartUploads002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + ListMultipartUploadsRequest request = new ListMultipartUploadsRequest("examplebucket"); + MultipartUploadListing result; + do { + result = obsClient.listMultipartUploads(request); + for (MultipartUpload upload : result.getMultipartTaskList()) { + System.out.println("UploadId:" + upload.getUploadId()); + System.out.println("ObjectKey:" + upload.getObjectKey()); + System.out.println("InitiatedDate:" + upload.getInitiatedDate()); + } + request.setKeyMarker(result.getNextKeyMarker()); + request.setUploadIdMarker(result.getNextUploadIdMarker()); + } while (result.isTruncated()); + System.out.println("ListMultipartUploads successfully"); + } catch (ObsException e) { + System.out.println("ListMultipartUploads failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("ListMultipartUploads failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS Java SDK provides abundant APIs for object download in the following methods:
+ +Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
isEncodeHeaders + |
+boolean + |
+No + |
+Whether to automatically encode the request header. The default value is true. + |
+
userHeaders + |
+HashMap<String, String> + |
+No + |
+User's header field. + |
+
ifMatchTag + |
+String + |
+No + |
+Returns the object content if the object's ETag is the same as this parameter value. Otherwise, an error is reported. + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Returns the object content if the object's ETag is different from this parameter value. Otherwise, an error is reported. + |
+
ifModifiedSince + |
+Date + |
+No + |
+Returns the object if it has been modified since the specified time; otherwise, an error is returned. + |
+
ifUnmodifiedSince + |
+Date + |
+No + |
+Returns the object if it has not been modified since the specified time; otherwise, an error is returned. + |
+
rangeStart + |
+Long + |
+No + |
+Start byte for a partial download. + |
+
rangeEnd + |
+Long + |
+No + |
+End byte for a partial download. + |
+
sseCHeader + |
+SseCHeader + |
+No + |
+Information about the server-side encryption header. + |
+
versionId + |
+String + |
+No + |
+Version number. + |
+
When you call ObsClient.getObject, an instance of ObsObject will be returned. This instance contains the contents of the object such as its name, attributes, input stream, and which bucket it is stored in. You can perform operations on the object input stream to read the contents to a local file or memory.
+obsClient.getObject(GetObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
rangeStart + |
+Long + |
+No + |
+Explanation: +Start position for object download. +Value range: +A non-negative integer. +Default value: +None + |
+
rangeEnd + |
+Long + |
+No + |
+Explanation: +End position for object download. +Restrictions: +The upper limit of the value is the object length minus 1, in bytes. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is the same as the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is different from the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
IfUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has not been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side decryption header. For details, see Table 7. + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +Additional information about the object. For details, see Table 3. + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the download progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating Advanced Encryption Standard (AES) is used to encrypt the object in SSE-C. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 8. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 11. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 10. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 4. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
This example downloads objectname from examplebucket using streaming.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsObject; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +public class GetObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Download the object using streaming. + ObsObject obsObject = obsClient.getObject("examplebucket", "objectname"); + // Read the object content. + System.out.println("Object content:"); + InputStream input = obsObject.getObjectContent(); + byte[] b = new byte[1024]; + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + int len; + while ((len = input.read(b)) != -1) { + bos.write(b, 0, len); + } + System.out.println("getObjectContent successfully"); + System.out.println(new String(bos.toByteArray())); + bos.close(); + input.close(); + } catch (ObsException e) { + System.out.println("getObjectContent failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectContent failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API downloads partial data of an object by specifying a range. If the specified range is from 0 to 1,000, data from byte 0 to byte 1,000, 1,001 bytes in total, are returned. If the specified range is invalid, the whole object is returned.
+obsClient.getObject(GetObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
rangeStart + |
+Long + |
+No + |
+Explanation: +Start position for object download. +Value range: +A non-negative integer. +Default value: +None + |
+
rangeEnd + |
+Long + |
+No + |
+Explanation: +End position for object download. +Restrictions: +The upper limit of the value is the object length minus 1, in bytes. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is the same as the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is different from the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
IfUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has not been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side decryption header. For details, see Table 7. + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +Additional information about the object. For details, see Table 3. + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the download progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating Advanced Encryption Standard (AES) is used to encrypt the object in SSE-C. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 8. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 11. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 10. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 12. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
This example downloads part of object objectname in bucket examplebucket by specifying a range from 0l to 1000l.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObsObject; +import java.io.InputStream; +public class GetObject002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Perform a partial download. + GetObjectRequest request = new GetObjectRequest("examplebucket", "objectname"); + // Set the start point and end point. + request.setRangeStart(0l); + request.setRangeEnd(1000l); + ObsObject obsObject = obsClient.getObject(request); + // Read data. + byte[] buf = new byte[1024]; + InputStream in = obsObject.getObjectContent(); + for (int n = 0; n != -1; ) { + n = in.read(buf, 0, buf.length); + } + System.out.println("GetObject successfully"); + in.close(); + } catch (ObsException e) { + System.out.println("GetObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("GetObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the download progress of a specified object.
+You can call GetObjectRequest.setProgressInterval to obtain the download progress.
+GetObjectRequest.setProgressListener(ProgressListener progressListener)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
progressListener + |
++ | +Yes + |
+Explanation: +Data transmission listener used for obtaining the progress. For details, see Table 2. + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 4. + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
This example returns the progress of downloading object objectname.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObsObject; +import com.obs.services.model.ProgressListener; +import com.obs.services.model.ProgressStatus; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +public class GetObject003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain the download progresses. + GetObjectRequest request = new GetObjectRequest("examplebucket", "objectname"); + request.setProgressListener( + new ProgressListener() { + @Override + public void progressChanged(ProgressStatus status) { + // Obtain the average download rate. + System.out.println("AverageSpeed:" + status.getAverageSpeed()); + // Obtain the download progress in percentage. + System.out.println("TransferPercentage:" + status.getTransferPercentage()); + } + }); + // Refresh the download progress each time 1 MB data is downloaded. + request.setProgressInterval(1024 * 1024L); + ObsObject obsObject = obsClient.getObject(request); + // Read the object content. + System.out.println("Object content:"); + InputStream input = obsObject.getObjectContent(); + byte[] b = new byte[1024]; + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + int len; + while ((len = input.read(b)) != -1) { + bos.write(b, 0, len); + } + System.out.println("getObjectContent successfully"); + System.out.println(new String(bos.toByteArray())); + bos.close(); + input.close(); + } catch (ObsException e) { + System.out.println("getObjectContent failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectContent failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the objects that meet one or more conditions. If there are no objects that meet the specified conditions, an error is returned.
+obsClient.getObject(GetObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
rangeStart + |
+Long + |
+No + |
+Explanation: +Start position for object download. +Value range: +A non-negative integer. +Default value: +None + |
+
rangeEnd + |
+Long + |
+No + |
+Explanation: +End position for object download. +Restrictions: +The upper limit of the value is the object length minus 1, in bytes. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +
Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +
Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+Date + |
+No + |
+Explanation: +
Default value: +None + |
+
IfUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +
Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side decryption header. For details, see Table 7. + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +Additional information about the object. For details, see Table 3. + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating Advanced Encryption Standard (AES) is used to encrypt the object in SSE-C. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 8. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 11. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 10. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 12. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
This example downloads objectname from examplebucket based on a specific condition. In this example, objectname can be downloaded only when it is modified after 00:00:00 on January 1, 2016.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObsObject; +import java.text.SimpleDateFormat; +public class GetObject004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Perform a conditional download. + GetObjectRequest request = new GetObjectRequest("examplebucket", "objectname"); + request.setRangeStart(0l); + request.setRangeEnd(1000l); + request.setIfModifiedSince(new SimpleDateFormat("yyyy-MM-dd").parse("2016-01-01")); + ObsObject obsObject = obsClient.getObject(request); + System.out.println("getObject successfully"); + obsObject.getObjectContent().close(); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API rewrites the following HTTP/HTTPS response headers when downloading an object: Content-Type, Content-Language, Expires, Cache-Control, Content-Disposition, and Content-Encoding.
+obsClient.getObject(GetObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
rangeStart + |
+Long + |
+No + |
+Explanation: +Start position for object download. +Value range: +A non-negative integer. +Default value: +None + |
+
rangeEnd + |
+Long + |
+No + |
+Explanation: +End position for object download. +Restrictions: +The upper limit of the value is the object length minus 1, in bytes. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is the same as the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is different from the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
IfUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has not been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side decryption header. For details, see Table 7. + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +Additional information about the object. For details, see Table 3. + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the progress. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating Advanced Encryption Standard (AES) is used to encrypt the object in SSE-C. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 8. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 11. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 10. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 12. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
This example rewrites response headers and downloads object objectname from bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObjectRepleaceMetadata; +import com.obs.services.model.ObsObject; +public class GetObject005 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Rewrite the response headers. + GetObjectRequest request = new GetObjectRequest("examplebucket", "objectname"); + ObjectRepleaceMetadata replaceMetadata = new ObjectRepleaceMetadata(); + replaceMetadata.setContentType("image/jpeg"); + request.setReplaceMetadata(replaceMetadata); + ObsObject obsObject = obsClient.getObject(request); + System.out.println(obsObject.getMetadata().getContentType()); + System.out.println("getObject successfully"); + obsObject.getObjectContent().close(); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Object metadata is a set of key-value pairs that describe the object and is used for object management.
+This API returns the user-defined object metadata after the object is successfully downloaded.
+obsClient.getObject(GetObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
rangeStart + |
+Long + |
+No + |
+Explanation: +Start position for object download. +Value range: +A non-negative integer. +Default value: +None + |
+
rangeEnd + |
+Long + |
+No + |
+Explanation: +End position for object download. +Restrictions: +The upper limit of the value is the object length minus 1, in bytes. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is the same as the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is different from the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
IfUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has not been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side decryption header. For details, see Table 7. + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +Additional information about the object. For details, see Table 3. + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the progress. For details, see Table 4. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating Advanced Encryption Standard (AES) is used to encrypt the object in SSE-C. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 8. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 11. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 10. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 12. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
This example downloads object objectname from bucket examplebucket and returns the user-defined object metadata.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.ObsObject; +import com.obs.services.model.PutObjectRequest; +public class GetObject006 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain the user-defined metadata. + // Upload the object and customize the metadata. + PutObjectRequest request = new PutObjectRequest("examplebucket", "objectname"); + ObjectMetadata metadata = new ObjectMetadata(); + metadata.addUserMetadata("property", "property-value"); + request.setMetadata(metadata); + obsClient.putObject(request); + // Download the object to obtain the object's user-defined metadata. + GetObjectRequest request1 = new GetObjectRequest("examplebucket", "objectname"); + ObsObject obsObject = obsClient.getObject(request1); + System.out.println("getObject successfully"); + // Get the object metadata. + System.out.println(obsObject.getMetadata().getContentType()); + // Obtain the user-defined metadata named property. + System.out.println(obsObject.getMetadata().getUserMetadata("property")); + // Obtain all user-defined metadata. + System.out.println("allUserMetadata:" + metadata.getAllMetadata()); + obsObject.getObjectContent().close(); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Cold objects must first be restored before you can download them. Cold objects can be restored in either of the following ways.
+ +Option + |
+Description + |
+Value in OBS Java SDK + |
+
|---|---|---|
Expedited + |
+Data can be restored within 1 to 5 minutes. + |
+RestoreTierEnum.EXPEDITED + |
+
Standard + |
+Data can be restored within 3 to 5 hours. This is the default option. + |
+RestoreTierEnum.STANDARD + |
+
obsClient.restoreObject(RestoreObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Version ID of the Cold object to be restored +Default value: +None. If this parameter is left blank, the latest version of the object is specified. + |
+
days + |
+int + |
+Yes + |
+Explanation: +After an object is restored, a Standard copy of it is generated. This parameter specifies how long the Standard copy can be retained, that is, the validity period of the restored object. +Restrictions: +The value must be a positive integer. +Value range: +The value ranges from 1 to 30, in days. +Default value: +None + |
+
tier + |
++ | +No + |
+Explanation: +The restore option, which indicates the time spent on restoring the object. +Value range: +For details, see Table 3. +Default value: +Standard + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example restores object objectname from the Cold storage class using ObsClient.restoreObject and downloads it using ObsClient.getObject.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsObject; +import com.obs.services.model.RestoreObjectRequest; +import com.obs.services.model.RestoreTierEnum; +public class GetObject007 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Restore the Cold object. + RestoreObjectRequest request = new RestoreObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setDays(1); + request.setRestoreTier(RestoreTierEnum.EXPEDITED); + obsClient.restoreObject(request); + // Wait for the object to be restored. + Thread.sleep(60 * 6 * 1000); + // Download the object. + ObsObject obsObject = obsClient.getObject("examplebucket", "objectname"); + System.out.println("getObject successfully"); + obsObject.getObjectContent().close(); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
obsClient.downloadFile(DownloadFileRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading a large object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
downloadFile + |
+String + |
+No + |
+Explanation: +Full path of the local directory to which the object is downloaded. +Default value: +If the value of this parameter is left blank, the downloaded object is saved in the directory where the program is executed. + |
+
partSize + |
+long + |
+No + |
+Explanation: +Part size. +Value range: +The value ranges from 100 KB to 5 GB, in bytes. +Default value: +9 MB + |
+
taskNum + |
+int + |
+No + |
+Explanation: +Maximum number of parts that can be downloaded concurrently in a multipart download +Value range: +The value must be greater than 0, but not exceed the file size divided by the part size, rounded up. +Default value: +1, indicating concurrent downloads are not used. + |
+
enableCheckpoint + |
+boolean + |
+No + |
+Explanation: +Whether to enable the resumable mode. +Value range: +true: The resumable mode is enabled. +false: The resumable mode is disabled. +Default value: +false + |
+
checkpointFile + |
+String + |
+No + |
+Explanation: +Path of a file generated for recording the progress of a resumable download. The file contains the information about parts and progress. +Restrictions: +This parameter is valid only in the resumable mode. +Default value: +If this parameter is left blank, the checkpoint file will be saved in the current directory. + |
+
enableCheckSum + |
+boolean + |
+No + |
+Explanation: +Whether to verify the file to download. If this function is enabled, before each task restarts, the system verifies whether the file to download is the one used during task initialization. +Restrictions: +This parameter is valid only in the resumable mode. +Value range: +true: The file is verified. +false: The file is not verified. +Default value: +false + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9. +Value range: +The value must contain 32 characters. +Default value: +None. If this parameter is left blank, the latest version of the object is obtained. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to automatically decode the response headers. +Default value: +None + |
+
ifModifiedSince + |
+Date + |
+No + |
+Explanation: +Returns the object if it has been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
ifUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +Returns the object if it has not been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Returns the object content if the object's ETag is the same as the value of this parameter. Otherwise, an error is reported. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Returns the object content if the object's ETag is different from the value of this parameter. Otherwise, an error is reported. +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the download progress. For details, see Table 3. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 4. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 5. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If this header is not set, the default storage class of the bucket is used as the storage class of the object. +Value range: +See Table 6. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
objectMetadata + |
++ | +Explanation: +Object metadata. For details, see Table 7. + |
+
This example downloads object objectname from bucket examplebucket to localfile using the resumable download.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.DownloadFileRequest; +import com.obs.services.model.DownloadFileResult; +public class DownloadFile001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + DownloadFileRequest request = new DownloadFileRequest("examplebucket", "objectname"); + // Set the local path the object will be downloaded to. + request.setDownloadFile("localfile"); + // Set the maximum number of parts that can be concurrently downloaded. + request.setTaskNum(5); + // Set the part size to 10 MB. + request.setPartSize(10 * 1024 * 1024); + // Enable the resumable upload. + request.setEnableCheckpoint(true); + // Perform a resumable download. + DownloadFileResult result = obsClient.downloadFile(request); + System.out.println("downloadFile successfully"); + System.out.println("Etag:" + result.getObjectMetadata().getEtag()); + } catch (ObsException e) { + System.out.println("downloadFile failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("downloadFile failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Object metadata is a set of name-value pairs that describe the object and is used for object management.
+Users with the READ permission on objects can send HEAD requests to retrieve metadata from objects. The metadata of the objects is included in the response.
+This operation supports server-side encryption.
+obsClient.getObjectMetadata(GetObjectMetadataRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for obtaining object metadata. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
userHeaders + |
+HashMap<String, String> + |
+No + |
+Explanation: +User header list. In HashMap, the String key and value indicate the name and value of the user header field respectively. The SDK does not process the userHeaders and instead transparently transmits it to the server for later use. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
sseHeader + |
++ | +No + |
+Explanation: +Server-side decryption headers. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 4. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 5. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +
Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
This example returns the metadata of object objectname in bucket examplebucket.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +public class GetObjectMetadata001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain the object metadata. + ObjectMetadata metadata = obsClient.getObjectMetadata("examplebucket", "objectname"); + System.out.println("getObjectMetadata successfully"); + System.out.println("ContentType:" + metadata.getContentType()); + System.out.println("ContentLength:" + metadata.getContentLength()); + // Obtain the user-defined metadata. + System.out.println("UserMetadata:" + metadata.getUserMetadata("property")); + // Obtain all original response headers. + System.out.println("OriginalHeaders:" + metadata.getOriginalHeaders()); + } catch (ObsException e) { + System.out.println("getObjectMetadata failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectMetadata failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over resources when a bucket or object is created. That is, the bucket creator has full control over the bucket, and the object uploader has full control over the object. Other accounts do not have the permissions to access resources. If resource owners want to grant other accounts the read and write permissions on resources, they can use ACLs. ACLs grant permissions to accounts. After an account is granted permissions, both the account and its IAM users can access the resources. If an object is encrypted with SSE-KMS, the ACL configured for it is not in effect in the cross-tenant case.
+ +An object ACL can be configured in any of the following ways:
+obsClient.setObjectAcl(SetObjectAclRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for setting an object ACL. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
acl + |
++ | +Yes + |
+Explanation: +An ACL specified for the object. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
owner + |
++ | +Yes + |
+Explanation: +Bucket owner information. For details, see Table 5. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 7. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 10. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 8. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 9. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example uploads localfile to bucket examplebucket as object objectname, and specifies a pre-defined ACl during the upload.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject012 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Specify a pre-defined ACL during object upload. + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setFile(new File("localfile")); + // Set the object ACL to private read and write. + request.setAcl(AccessControlList.REST_CANNED_PRIVATE); + obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example specifies a pre-defined ACL of private read and write for object objectname in examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +public class SetObjectAcl001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set a predefined ACL for the object. + // Set the object ACL to private read and write. + obsClient.setObjectAcl("examplebucket", "objectname", AccessControlList.REST_CANNED_PRIVATE); + System.out.println("setObjectAcl successfully"); + } catch (ObsException e) { + System.out.println("setObjectAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setObjectAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example configures an ACL for object objectname in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.CanonicalGrantee; +import com.obs.services.model.GroupGrantee; +import com.obs.services.model.Owner; +import com.obs.services.model.Permission; +public class SetObjectAcl002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + AccessControlList acl = new AccessControlList(); + Owner owner = new Owner(); + owner.setId("ownerid"); + // (Mandatory) Owner ID + acl.setOwner(owner); + //Retain the owner's full control permissions. (Note that if this permission is not set, the owner does not have the access permission.) + acl.grantPermission(new CanonicalGrantee("ownerid"), Permission.PERMISSION_FULL_CONTROL); + // Grant the full control permission to a specified user. + acl.grantPermission(new CanonicalGrantee("userid"), Permission.PERMISSION_FULL_CONTROL); + // Grant the read permission to all users. + acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ); + obsClient.setObjectAcl("examplebucket", "objectname", acl); + System.out.println("setObjectAcl successfully"); + System.out.println(acl); + } catch (ObsException e) { + System.out.println("setObjectAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setObjectAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API lists some or all of the objects in a bucket. You can use parameters such as the prefix, number of returned objects, and start position to list objects that meet specified criteria. Returned objects are listed in alphabetical order by object name.
+obsClient.listObjects(ListObjectsRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for listing the objects in a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
prefix + |
+String + |
+No + |
+Explanation: +Name prefix that the objects to be listed must contain. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, logs/day1, logs/day2, and logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all objects in the bucket will be returned. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
marker + |
+String + |
+No + |
+Explanation: +Name of the object to start with when listing objects in a bucket. All objects following this object are listed in alphabetical order by object name. +Assume that you have the following objects: test/a, test/b, test/c, and test/d. If you specify test/b as the marker, test/c and test/d are returned. +Restrictions: +This parameter is only available for listing objects with a single version. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
maxKeys + |
+int + |
+No + |
+Explanation: +The maximum number of objects returned in the response in alphabetical order. +Value range: +The value ranges from 1 to 1000. If the specified value is beyond this range, only 1,000 objects are returned. +Default value: +1000 + |
+
delimiter + |
+String + |
+No + |
+Explanation: +Object names are grouped by this parameter, which is often used with Prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one CommonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one CommonPrefixes. +Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, files abcd and abcde are grouped into a CommonPrefixes with abcd as the prefix. If only delimiter is set to d, files abcd and abcde are grouped into a CommonPrefixes with abcd as the prefix, and bbcde is grouped separately into another CommonPrefixes with bbcd as the prefix. +For a PFS, if this parameter is not specified, all the contents in the current directory are recursively listed by default, and subdirectories are also listed. In big data scenarios, PFSs usually have multiple directory levels and each directory level has a large number of files. In such case, you are advised to configure [delimiter=/] to list the contents in the current directory but exclude the contents in subdirectories, thereby accelerating the listing. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
prefix + |
+String + |
+Explanation: +Object name prefix. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, logs/day1, logs/day2, and logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all objects in the bucket will be returned. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
objectSummaries + |
+List<ObsObject> + |
+Explanation: +List of objects in the bucket. For details, see Table 4. + |
+
commonPrefixes + |
+List<String> + |
+Explanation: +List of object name prefixes grouped according to the delimiter parameter (if specified) +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
truncated + |
+boolean + |
+Explanation: +Whether all objects are returned in the response. A maximum of 1,000 objects can be listed at a time. If the number of objects is greater than 1,000, the objects beyond 1,000 cannot be returned. +Value range: +true: Not all objects are returned. +false: All objects are returned. +Default value: +None + |
+
marker + |
+String + |
+Explanation: +Where in the bucket the listing starts from. All objects following the object specified by this parameter are listed in alphabetical order by object name. Assume you have the following objects: test/a, test/b, test/c, and test/d. If you specify test/b as the marker, test/c and test/d are returned. +Restrictions: +This parameter is only available for listing objects with a single version. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
maxKeys + |
+int + |
+Explanation: +The maximum number of objects returned in the response in alphabetical order. +Value range: +The value ranges from 1 to 1000. If the specified value is beyond this range, only 1,000 objects are returned. +Default value: +1000 + |
+
delimiter + |
+String + |
+Explanation: +Object names are grouped by this parameter, which is often used with Prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one CommonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one CommonPrefixes. +Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, files abcd and abcde are grouped into a CommonPrefixes with abcd as the prefix. If only delimiter is set to d, files abcd and abcde are grouped into a CommonPrefixes with abcd as the prefix, and bbcde is grouped separately into another CommonPrefixes with bbcd as the prefix. +For a PFS, if this parameter is not specified, all the contents in the current directory are recursively listed by default, and subdirectories are also listed. In big data scenarios, PFSs usually have multiple directory levels and each directory level has a large number of files. In such case, you are advised to configure [delimiter=/] to list the contents in the current directory but exclude the contents in subdirectories, thereby accelerating the listing. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
nextMarker + |
+String + |
+Explanation: +Where in the bucket the next listing begins. If not all objects are returned, the response contains this parameter to mark the last object returned for the current request. You can use the value of this parameter as the value of Marker in the subsequent request to list the remaining objects. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
location + |
+String + |
+Explanation: +Region where a bucket is located. +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectContent + |
+InputStream + |
+Explanation: +The data stream of the object. +Default value: +None + |
+
owner + |
++ | +Explanation: +Object owner. This parameter contains the domain ID and name of the object owner. For details, see Table 5. +Default value: +None + |
+
metadata + |
++ | +Explanation: +Object metadata. +Value range: +Object metadata. For details, see Table 7. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the object data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 6. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
This example lists objects in bucket examplebucket. A maximum of 1,000 objects can be returned.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Listing objects. + ObjectListing result = obsClient.listObjects("examplebucket"); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists a specified number of objects in bucket examplebucket. A maximum of 100 objects can be listed.
+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 +49 +50 +51 +52 +53 +54 +55 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListObjectsRequest; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List a specified number of objects. + ListObjectsRequest request = new ListObjectsRequest("examplebucket"); + // Set the number of objects to be listed to 100. + request.setMaxKeys(100); + ObjectListing result = obsClient.listObjects(request); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example specifies a prefix to list objects in bucket examplebucket. A maximum of 100 objects can be listed.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListObjectsRequest; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List objects by specifying a prefix. + ListObjectsRequest request = new ListObjectsRequest("examplebucket"); + // List 100 objects with the specified prefix. + request.setMaxKeys(100); + request.setPrefix("prefix"); + ObjectListing result = obsClient.listObjects(request); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example specifies a start position to list objects in bucket examplebucket. A maximum of 100 objects can be listed.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListObjectsRequest; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List objects by specifying the start position. + ListObjectsRequest request = new ListObjectsRequest("examplebucket"); + // Specify that 100 objects whose names follow test in lexicographical order will be listed. + request.setMaxKeys(100); + request.setMarker("test"); + ObjectListing result = obsClient.listObjects(request); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists all objects in bucket examplebucket using pagination. A maximum of 100 objects can be listed on each page.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListObjectsRequest; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects005 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List all objects using pagination. + ListObjectsRequest request = new ListObjectsRequest("examplebucket"); + // Set the number of objects displayed per page to 100. + request.setMaxKeys(100); + ObjectListing result; + do { + result = obsClient.listObjects(request); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + request.setMarker(result.getNextMarker()); + } while (result.isTruncated()); + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
There is no concept of folders in OBS. All elements stored in OBS buckets are objects. Folders are actually objects whose sizes are 0 and whose names end with a slash (/). You can set a folder name as a prefix to list objects in this folder. This example lists objects in a folder.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListObjectsRequest; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects006 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + //List all objects in a folder. + ListObjectsRequest request = new ListObjectsRequest("examplebucket"); + // Set folder name dir/ as the prefix. + request.setPrefix("dir/"); + request.setMaxKeys(100); + ObjectListing result; + do { + result = obsClient.listObjects(request); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + request.setMarker(result.getNextMarker()); + } while (result.isTruncated()); + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists all objects in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListObjectsRequest; +import com.obs.services.model.ObjectListing; +import com.obs.services.model.ObsObject; +public class ListObjects007 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List all objects in the root directory. + ListObjectsRequest request = new ListObjectsRequest("examplebucket"); + request.setMaxKeys(1000); + // Set folder isolators to slashes (/). + request.setDelimiter("/"); + ObjectListing result = obsClient.listObjects(request); + System.out.println("Objects in the root directory:"); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("listObjects successfully"); + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + listObjectsByPrefix(obsClient, request, result); + } catch (ObsException e) { + System.out.println("listObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } + |
This example recursively lists objects in a sub-folder.
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 | // Recursively list objects in a sub-folder. + static void listObjectsByPrefix(ObsClient obsClient, ListObjectsRequest request, ObjectListing result) + throws ObsException { + for (String prefix : result.getCommonPrefixes()) { + System.out.println("Objects in folder [" + prefix + "]:"); + request.setPrefix(prefix); + result = obsClient.listObjects(request); + for (ObsObject obsObject : result.getObjects()) { + System.out.println("ObjectKey:" + obsObject.getObjectKey()); + System.out.println("Owner:" + obsObject.getOwner()); + } + listObjectsByPrefix(obsClient, request, result); + } + } +} + |
This API deletes objects from a specific bucket.
+obsClient.deleteObject(DeleteObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for deleting an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
deleteMarker + |
+boolean + |
+Explanation: +Whether the deleted object is a delete marker. +Value range: +
Default value: +false + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
This example deletes object objectname from bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete the object. + obsClient.deleteObject("examplebucket", "objectname"); + System.out.println("deleteObject successfully"); + } catch (ObsException e) { + System.out.println("deleteObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API copies an object stored in OBS to another path, with a copy created during the process. You can create a copy of an object up to 5 GB in a single operation.
+obsClient.copyObject(CopyObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for copying an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Target bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Target object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header used for encrypting the target object. For details, see Table 3. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header used for encrypting the target object. For details, see Table 4. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL specified for the object. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
successRedirectLocation + |
+String + |
+No + |
+Explanation: +Address (URL) to which a successfully answered request is redirected. +
Default value: +None + |
+
sourceBucketName + |
+String + |
+Yes + |
+Explanation: +Name of the source bucket. +Restrictions: +
Default value: +None + |
+
sourceObjectKey + |
+String + |
+Yes + |
+Explanation: +Source object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
newObjectMetadata + |
++ | +No + |
+Explanation: +User-defined metadata of the target object. For details, see Table 16. +Restrictions: +replaceMetadata must be used together with newObjectMetadata. +Default value: +None + |
+
replaceMetadata + |
+boolean + |
+No + |
+Explanation: +Whether to rewrite the metadata of the source object. +Restrictions: +replaceMetadata must be used together with newObjectMetadata. +Value range: +true: The metadata of the source object is rewritten. +false: The metadata of the source object is not rewritten. +Default value: +None + |
+
ifModifiedSince + |
+java.util.Date + |
+No + |
+Explanation: +The source object is copied if it has been modified since the specified time; otherwise, an exception is thrown. +Restrictions: +
Default value: +None + |
+
ifUnmodifiedSince + |
+java.util.Date + |
+No + |
+Explanation: +If the source object has not been modified since the specified time, it is copied. Otherwise, an exception is thrown. +Restrictions: +
Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the source object is the same as the preset ETag, the object is returned. Otherwise, an error is returned. The ETag of the source object is the MD5 value of it. +Restrictions: +
Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the source object is different from the preset ETag, the object is returned. Otherwise, an error is returned. The ETag of the source object is the MD5 value of it. +Restrictions: +
Value range: +The value must contain 32 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Source object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
sseCHeaderSource + |
++ | +No + |
+Explanation: +Server-side decryption header used for decrypting the source object. For details, see Table 4. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 5. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 6. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 7. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 6. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 10. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 11. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 13. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 12. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 14. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 15. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 17. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
lastModified + |
+java.util.Date + |
+Explanation: +Last time the target object was modified. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of the target object. Base64-encoded, 128-bit MD5 value of an object. ETag is the unique identifier of the object contents and is used to determine whether the contents of an object are changed. For example, if the ETag value is A when an object is uploaded and is B when the object is downloaded, this indicates the contents of the object are changed. The ETag reflects changes only to the contents of an object, not its metadata. Objects created by the upload and copy operations have unique ETags after being encrypted using MD5. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Version ID of the target object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
copySourceVersionId + |
+String + |
+Explanation: +Version ID of the source object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of the target object. +Value range: +See Table 17. +Default value: +None + |
+
This example copies object sourceobjectname from bucket sourcebucketname to bucket destbucketname as object destobjectname.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CopyObjectResult; +public class CopyObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Copy an object. + CopyObjectResult result = + obsClient.copyObject("sourcebucketname", "sourceobjectname", "destbucketname", "destobjectname"); + System.out.println("copyObject successfully"); + System.out.println("StatusCode:" + result.getStatusCode()); + System.out.println("Etag:" + result.getEtag()); + } catch (ObsException e) { + System.out.println("copyObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("copyObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example rewrites object attributes when object sourceobjectname is copied from bucket sourcebucketname to bucket destbucketname as object destobjectname.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CopyObjectRequest; +import com.obs.services.model.CopyObjectResult; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.StorageClassEnum; +public class CopyObject002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Rewrite object attributes when copying an object. + CopyObjectRequest request = new CopyObjectRequest("sourcebucketname", "sourceobjectname", "destbucketname", "destobjectname"); + // Rewrite object attributes. + request.setReplaceMetadata(true); + HashMap<String, String> userHeaders = new HashMap<>(); + userHeaders.put("Content-Type","image/jpeg"); + request.setUserHeaders(userHeaders); + CopyObjectResult result = obsClient.copyObject(request); + System.out.println("copyObject successfully"); + System.out.println("Etag:" + result.getEtag()); + } catch (ObsException e) { + System.out.println("copyObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("copyObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example specifies conditions when object sourceobjectname is copied from bucket sourcebucketname to bucket destbucketname as object destobjectname.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CopyObjectRequest; +import com.obs.services.model.CopyObjectResult; +import java.text.SimpleDateFormat; +public class CopyObject003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set conditions for the copy. + CopyObjectRequest request = + new CopyObjectRequest("sourcebucketname", "sourceobjectname", "destbucketname", "destobjectname"); + request.setIfModifiedSince(new SimpleDateFormat("yyyy-MM-dd").parse("2016-01-01")); + request.setIfNoneMatchTag("none-match-etag"); + CopyObjectResult result = obsClient.copyObject(request); + System.out.println("copyObject successfully"); + System.out.println("Etag:" + result.getEtag()); + } catch (ObsException e) { + System.out.println("copyObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("copyObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example rewrites the object ACL when object sourceobjectname is copied from bucket sourcebucketname to bucket destbucketname as object destobjectname.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.CopyObjectRequest; +import com.obs.services.model.CopyObjectResult; +public class CopyObject004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Rewrite the object ACL when copying the object. + CopyObjectRequest request = + new CopyObjectRequest("sourcebucketname", "sourceobjectname", "destbucketname", "destobjectname"); + // Rewrite the object ACL to Private. + request.setAcl(AccessControlList.REST_CANNED_PRIVATE); + CopyObjectResult result = obsClient.copyObject(request); + System.out.println("copyObject successfully"); + System.out.println("Etag:" + result.getEtag()); + } catch (ObsException e) { + System.out.println("copyObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("copyObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Object metadata is a set of name-value pairs that describe the object and is used for object management.
+Currently, only the system-defined metadata is supported.
+There are two kinds of metadata: system-controlled metadata and user-controlled metadata. The kind of metadata like Last-Modified is controlled by the system and cannot be modified. However, the kind of metadata configured for objects such as ContentLanguage can be modified by calling APIs.
+This API sends a HEAD request to configure the metadata of an object in a specified bucket.
+obsClient.setObjectMetadata(SetObjectMetadataRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for obtaining object metadata. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of the object. +Value range: +See Table 3. +Default value: +None + |
+
removeUnset + |
+boolean + |
+No + |
+Explanation: +Whether to delete the previously configured metadata if the request is successful. +Value range: +true: If the API is successfully invoked, the previous metadata will be deleted. Standard metadata is not affected. For user-defined metadata, only the new metadata is retained. +false: The previous metadata will not be deleted even if the API is successfully invoked. Standard metadata is not affected. For user-defined metadata, only the new metadata is retained. +Default value: +false + |
+
userMetadata + |
+Map<String, String> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key and value indicate the name and value of the user-defined metadata respectively. After the metadata is defined, when you later download the object or query its metadata, the user-defined metadata is returned in the response. +Restrictions: +
Default value: +None + |
+
userHeaders + |
+HashMap<String, String> + |
+No + |
+Explanation: +User header list. In HashMap, the String key and value indicate the name and value of the user header field respectively. The SDK does not process the userHeaders and instead transparently transmits it to the server for later use. +Default value: +None + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +It specifies the metadata returned when the object is downloaded. For details, see Table 4. + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class. + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +It specifies the content encoding format when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the object data. It is provided for the OBS server to verify data integrity. +Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Object storage class. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 3. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. +Default value: +None + |
+
statusCode + |
+int + |
+This parameter is automatically set in the response. + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+This parameter is automatically set in the response. + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures metadata for object objectname by specifying the user-defined metadata and using userHeaders that are transparently transmitted.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.SetObjectMetadataRequest; +import java.util.HashMap; +public class SetObjectMetadata001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Configure metadata for the object. + SetObjectMetadataRequest request = new SetObjectMetadataRequest("examplebucket", "objectname"); + // Standard HTTP headers of an object + request.setContentType("ContentType"); + request.setExpires("Expires"); + // During the user-defined metadata setting, the SDK automatically adds x-obs-meta-. + request.addUserMetadata("property1", "property-value1"); + HashMap<String, String> userHeaders = new HashMap<>(); + // userHeaders set by the SDK are transparently transmitted. They are not processed so they can be used more flexibly later. If a userHeader needs to be displayed as user-defined metadata on the server, add x-obs-meta- before the userHeader for the server to identify. + userHeaders.put("property2", "property-value2"); + userHeaders.put("x-obs-meta-property3", "property-value3"); + request.setUserHeaders(userHeaders); + ObjectMetadata metadata = obsClient.setObjectMetadata(request); + System.out.println("setObjectMetadata successfully"); + System.out.println("UserMetadata:" + metadata.getUserMetadata("property1")); + } catch (ObsException e) { + System.out.println("setObjectMetadata failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setObjectMetadata failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
After you run the sample code above and configure the user-defined metadata property1 and user headers property2 and x-obs-meta-property3, the HTTP header in the packet capture is as follows:
+
If you want to delete some metadata by calling the API for setting object metadata, configure the metadata to be retained and set SetObjectMetadataRequest.setRemoveUnset to true. Then, once the API is called, the data whose metadata is not configured will be deleted. Therefore, exercise caution when using SetObjectMetadataRequest.setRemoveUnset(true).
+This example deletes the user-defined metadata of object objectname in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.SetObjectMetadataRequest; +import java.util.HashMap; +public class SetObjectMetadata002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + SetObjectMetadataRequest request = new SetObjectMetadataRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setRemoveUnset(true); + HashMap<String, String> userHeaders = new HashMap<>(); + // After request.setRemoveUnset is set to true, the server saves metadata property1 and deletes the user-defined metadata saved before. + userHeaders.put("x-obs-meta-property1", "property-value1"); + request.setUserHeaders(userHeaders); + obsClient.setObjectMetadata(request); + System.out.println("setObjectMetadata successfully"); + } catch (ObsException e) { + System.out.println("setObjectMetadata failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setObjectMetadata failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API checks whether an object exists. If the returned HTTP status code is 200, the object exists. If the returned HTTP status code is 404, the object or bucket does not exist.
+doesObjectExist(final GetObjectMetadataRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
userHeaders + |
+HashMap<String, String> + |
+No + |
+Explanation: +User header list. In HashMap, the String key and value indicate the name and value of the user header field respectively. The SDK does not process the userHeaders and instead transparently transmits it to the server for later use. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to encode and decode HTTP headers. +Value range: +true: HTTP headers are encoded and decoded. +false: HTTP headers are not encoded or decoded. +Default value: +true + |
+
sseHeader + |
++ | +No + |
+Explanation: +Server-side decryption headers. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 4. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 5. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
doesObjectExist(final GetObjectMetadataRequest request) + |
+boolean + |
+Whether the object exists in the bucket. + |
+
This example checks whether object objectname exists in bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DoesObjectExist001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Check whether the specified object exists. + System.out.println(obsClient.doesObjectExist("examplebucket", "objectname") ? "exists!" : "does not exist!"); + System.out.println("doesObjectExist successfully"); + } catch (ObsException e) { + System.out.println("doesObjectExist failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("doesObjectExist failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Access control lists (ACLs) allow resource owners to grant other accounts the permissions to access resources. By default, only the resource owner has full control over resources when a bucket or object is created. That is, the bucket creator has full control over the bucket, and the object uploader has full control over the object. Other accounts do not have the permissions to access resources. If resource owners want to grant other accounts the read and write permissions on resources, they can use ACLs. ACLs grant permissions to accounts. After an account is granted permissions, both the account and its IAM users can access the resources. If an object is encrypted with SSE-KMS, the ACL configured for it is not in effect in the cross-tenant case.
+ +This API obtains the ACL of an object in a specified bucket.
+obsClient.getObjectAcl(GetObjectAclRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
+GetObjectAclRequest + |
+Yes + |
+Explanation: +Request parameters for obtaining an object ACL. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
owner + |
++ | +Explanation: +Object owner. For details, see Table 8. + |
+
grants + |
+Set<GrantAndPermission> + |
+Explanation: +Grantee information. For details, see Table 4. + |
+
delivered + |
+boolean + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 5. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 9. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 6. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 7. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
This example returns the ACL information of object objectname in bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +public class GetObjectAcl001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain the object ACL. + AccessControlList acl = obsClient.getObjectAcl("examplebucket", "objectname"); + System.out.println("getObjectAcl successfully"); + System.out.println(acl); + } catch (ObsException e) { + System.out.println("getObjectAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API deletes objects in batches from a specific bucket. Deleted objects cannot be recovered.
+In a batch delete operation, OBS concurrently deletes the specified objects and returns the deletion result of each object.
+obsClient.deleteObjects(DeleteObjectsRequest deleteRequest)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
deleteRequest + |
++ | +Yes + |
+Explanation: +Request parameters for deleting objects in batches. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
keyAndVersions + |
+List<KeyAndVersion> + |
+Yes + |
+Explanation: +List of objects to be deleted. For details, see Table 3. + |
+
quiet + |
+boolean + |
+No + |
+Explanation: +Response mode to the request for deleting objects in a batch. +Value range: +
Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
key + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None. If this parameter is left blank, the latest version of the object is deleted. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
deletedObjectResults + |
+List<DeleteObjectResult> + |
+Explanation: +Response results of the request for deleting objects in a batch. For details, see Table 5. + |
+
errorResults + |
+List<ErrorResult> + |
+Explanation: +List of objects that fail to be deleted. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
deleteMarker + |
+boolean + |
+Explanation: +Whether the deleted object is a delete marker. +Value range: +
Default value: +false + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
versionId + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
errorCode + |
+String + |
+Explanation: +Error code for the failed deletion. + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
message + |
+String + |
+Explanation: +Error message for the failed deletion. + |
+
This example deletes all objects whose names start with exampleObjectPrefix in bucket example-bucket in a batch. Note that if exampleObjectPrefix is left blank, all objects in the bucket will be deleted.
+import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.DeleteObjectsRequest; +import com.obs.services.model.DeleteObjectsResult; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +import java.util.Map; + +public class DeleteObjects002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + // String endPoint = System.getenv("ENDPOINT"); + + // Create a single instance of ObsClient. + // Use a permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use a temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + String exampleBucket = "example-bucket"; + String exampleObjectPrefix = "exampleObjectPrefix"; + // Batch delete the objects. + ListVersionsRequest request = new ListVersionsRequest(exampleBucket); + // Delete 100 objects at a time. + request.setMaxKeys(100); + request.setPrefix(exampleObjectPrefix); + ListVersionsResult result; + do { + result = obsClient.listVersions(request); + DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(exampleBucket); + // deleteRequest.setQuiet(true); + // This example uses the verbose mode. To use the quiet mode, add this line of code. + for (VersionOrDeleteMarker v : result.getVersions()) { + // Obtain object names and version IDs. + deleteRequest.addKeyAndVersion(v.getKey(), v.getVersionId()); + } + if(deleteRequest.getKeyAndVersions().length > 0){ + DeleteObjectsResult deleteResult = obsClient.deleteObjects(deleteRequest); + // Print the deleted objects. + System.out.println("DeletedObjectResults:"+ deleteResult.getDeletedObjectResults()); + // Print the objects that were not deleted. + System.out.println("ErrorResults:"+ deleteResult.getErrorResults()); + }else{ + System.out.println("No object to delete"); + } + request.setKeyMarker(result.getNextKeyMarker()); + // If versioning is not enabled, do not configure VersionIdMarker. + request.setVersionIdMarker(result.getNextVersionIdMarker()); + } while (result.isTruncated()); + System.out.println("deleteObjects successfully"); + } catch (ObsException e) { + System.out.println("deleteObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + Map<String, String> headers = e.getResponseHeaders();// Check Map entries and print all headers associated with the error. + if(headers != null){ + for (Map.Entry<String, String> header : headers.entrySet()) { + if(header.getKey().contains("error")){ + System.out.println(header.getKey()+":"+header.getValue()); + } + } + } + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObjects failed"); + // Print other error details. + e.printStackTrace(); + } + } +}+
This example batch deletes all objects in bucket examplebucket. Exercise caution when performing this operation.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.DeleteObjectsRequest; +import com.obs.services.model.DeleteObjectsResult; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class DeleteObjects001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Batch delete the objects. + ListVersionsRequest request = new ListVersionsRequest("examplebucket"); + // Delete 100 objects at a time. + request.setMaxKeys(100); + ListVersionsResult result; + do { + result = obsClient.listVersions(request); + DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest("examplebucket"); + // deleteRequest.setQuiet(true); // This example uses the verbose mode. To use the quiet mode, add this line of code. + for (VersionOrDeleteMarker v : result.getVersions()) { + // Obtain objects' names and version IDs. + deleteRequest.addKeyAndVersion(v.getKey(), v.getVersionId()); + } + if(deleteRequest.getKeyAndVersions().length > 0){ + DeleteObjectsResult deleteResult = obsClient.deleteObjects(deleteRequest); + // Print the deleted objects. + System.out.println("DeletedObjectResults:"+ deleteResult.getDeletedObjectResults()); + // Print the objects that were not deleted. + System.out.println("ErrorResults:"+ deleteResult.getErrorResults()); + }else{ + System.out.println("No object to delete"); + } + request.setKeyMarker(result.getNextKeyMarker()); + // If versioning is not enabled, do not configure VersionIdMarker. + request.setVersionIdMarker(result.getNextVersionIdMarker()); + } while (result.isTruncated()); + System.out.println("deleteObjects successfully"); + } catch (ObsException e) { + System.out.println("deleteObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example deletes all objects in the test folder in the examplebucket bucket with versioning disabled.
+import com.obs.services.ObsClient;
+import com.obs.services.ObsConfiguration;
+import com.obs.services.exception.ObsException;
+import com.obs.services.model.*;
+import java.io.IOException;
+import java.util.Map;
+
+public class Delete_Objects_test {
+ public static void main(String[] args) throws IOException {
+ // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ String ak = System.getenv("ACCESS_KEY_ID");
+ String sk = System.getenv("SECRET_ACCESS_KEY_ID");
+ // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage.
+ // Obtain an AK/SK pair and a security token using environment variables or import them in other ways.
+ // String securityToken = System.getenv("SECURITY_TOKEN");
+ // Enter the endpoint corresponding to the region where the bucket is located.
+ String endPoint = "https://your-endpoint";
+ // Obtain an endpoint using environment variables or import it in other ways.
+ // String endPoint = System.getenv("ENDPOINT");
+
+ // Create a single instance of ObsClient.
+ // Use a permanent AK/SK pair to initialize the client.
+ ObsClient obsClient = new ObsClient(ak, sk,endPoint);
+ // Use a temporary AK/SK pair and security token to initialize the client.
+ // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint);
+ try {
+ String exampleBucket = "examplebucket";
+ String exampleObjectPrefix = "test/";
+ ListObjectsRequest listObjectsRequest = new ListObjectsRequest(exampleBucket);
+ listObjectsRequest.setMaxKeys(100);
+ listObjectsRequest.setPrefix(exampleObjectPrefix);
+ ObjectListing objectListing;
+
+ do {
+ objectListing = obsClient.listObjects(listObjectsRequest);
+ DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(exampleBucket);
+ // This example uses the verbose mode. To use the quiet mode, add this line of code.
+ deleteRequest.setQuiet(true);
+ for (ObsObject object : objectListing.getObjects()) {
+ deleteRequest.addKeyAndVersion(object.getObjectKey(), null);
+ }
+
+ if (deleteRequest.getKeyAndVersions().length > 0) {
+ DeleteObjectsResult deleteResult = obsClient.deleteObjects(deleteRequest);
+ // Print the deleted objects.
+ System.out.println("DeletedObjectResults:" + deleteResult.getDeletedObjectResults());
+ // Print the objects that were not deleted.
+ System.out.println("ErrorResults:" + deleteResult.getErrorResults());
+ } else {
+ System.out.println("No object to delete");
+ }
+ listObjectsRequest.setMarker(objectListing.getNextMarker());
+ } while (objectListing.isTruncated());
+ System.out.println("deleteObjects successfully");
+ } catch (ObsException e) {
+ System.out.println("deleteObjects failed");
+ // Request failed. Print the HTTP status code.
+ System.out.println("HTTP Code:" + e.getResponseCode());
+ // Request failed. Print the server-side error code.
+ System.out.println("Error Code:" + e.getErrorCode());
+ // Request failed. Print the error details.
+ System.out.println("Error Message:" + e.getErrorMessage());
+ // Request failed. Print the request ID.
+ System.out.println("Request ID:" + e.getErrorRequestId());
+ System.out.println("Host ID:" + e.getErrorHostId());
+ Map<String, String> headers = e.getResponseHeaders();
+ // Check all Map entries and print all headers associated with the error.
+ if (headers != null) {
+ for (Map.Entry<String, String> header : headers.entrySet()) {
+ if (header.getKey().contains("error")) {
+ System.out.println(header.getKey() + ":" + header.getValue());
+ }
+ }
+ }
+ e.printStackTrace();
+ } catch (Exception e) {
+ System.out.println("deleteObjects failed");
+ // Print other error details.
+ e.printStackTrace();
+ }
+
+}
+}
+This API allows you to upload a part by copying an object or part of this object.
+You can call ObsClient.copyPart to copy parts.
+obsClient.copyPart(CopyPartRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for copying an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
sourceBucketName + |
+String + |
+Yes + |
+Explanation: +Name of the source bucket. +Restrictions: +
Default value: +None + |
+
sourceObjectKey + |
+String + |
+Yes + |
+Explanation: +Source object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
destinationBucketName + |
+String + |
+Yes + |
+Explanation: +Target bucket name. +Restrictions: +
Default value: +None + |
+
destinationObjectKey + |
+String + |
+Yes + |
+Explanation: +Target object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
byteRangeStart + |
+Long + |
+No + |
+Explanation: +Start position for the multipart copy +Value range: +A non-negative integer, in bytes. +Default value: +0 + |
+
byteRangeEnd + |
+Long + |
+No + |
+Explanation: +End position for the multipart copy +Restrictions: +The value must be greater than that of RangeStart. The upper limit of the value is the object length minus 1, in bytes. +Value range: +A non-negative integer, in bytes. +Default value: +None + |
+
sseCHeaderSource + |
++ | +No + |
+Explanation: +Server-side header used for decrypting the source object. For details, see Table 3. + |
+
sseCHeaderDestination + |
++ | +No + |
+Explanation: +Server-side encryption header used for encrypting the target object. For details, see Table 3. +Restrictions: +If the object uploaded to a server is encrypted with the key provided by the client, the key must also be provided in the message for downloading the object. + |
+
versionId + |
+String + |
+No + |
+Explanation: +Version ID of the source object, for example, G001117FCE89978B0000401205D5DC9A. If the source object has multiple versions, you can specify this parameter. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
partNumber + |
+int + |
+Yes + |
+Explanation: +Part number. +Value range: +An integer ranging from 1 to 10000 +Default value: +None + |
+
uploadId + |
+String + |
+Yes + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 4. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 5. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
partNumber + |
+int + |
+Explanation: +Part number. +Value range: +An integer ranging from 1 to 10000. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
lastModified + |
+java.util.Date + |
+Explanation: +Last time the target part was modified. +Default value: +None + |
+
This example copies object sourceobjectname in parts from bucket sourcebucketname to bucket destbucketname as object destobjectname.
+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 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CompleteMultipartUploadRequest; +import com.obs.services.model.CopyPartRequest; +import com.obs.services.model.CopyPartResult; +import com.obs.services.model.InitiateMultipartUploadRequest; +import com.obs.services.model.InitiateMultipartUploadResult; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.PartEtag; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +public class CopyPart001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Copy parts. + final String destBucketName = "destbucketname"; + final String destObjectKey = "destobjectname"; + final String sourceBucketName = "sourcebucketname"; + final String sourceObjectKey = "sourceobjectname"; + // Initialize the thread pool. + ExecutorService executorService = Executors.newFixedThreadPool(20); + // Initiate a multipart upload. + InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(destBucketName, destObjectKey); + InitiateMultipartUploadResult result = obsClient.initiateMultipartUpload(request); + final String uploadId = result.getUploadId(); + System.out.println("uploadId:" + uploadId + "\n"); + // Obtain information about the large object. + ObjectMetadata metadata = obsClient.getObjectMetadata(sourceBucketName, sourceObjectKey); + // Set the part size to 100 MB. + long partSize = 100 * 1024 * 1024L; + long objectSize = metadata.getContentLength(); + // Calculate the number of parts to be copied. + long partCount = objectSize % partSize == 0 ? objectSize / partSize : objectSize / partSize + 1; + final List<PartEtag> partEtags = Collections.synchronizedList(new ArrayList<>()); + // Start copying parts concurrently. + for (int i = 0; i < partCount; i++) { + // Start position for copying parts + final long rangeStart = i * partSize; + // End position for copying parts + final long rangeEnd = (i + 1 == partCount) ? objectSize - 1 : rangeStart + partSize - 1; + // Set the part number. + final int partNumber = i + 1; + executorService.execute( + new Runnable() { + @Override + public void run() { + CopyPartRequest request = new CopyPartRequest(); + request.setUploadId(uploadId); + request.setSourceBucketName(sourceBucketName); + request.setSourceObjectKey(sourceObjectKey); + request.setDestinationBucketName(destBucketName); + request.setDestinationObjectKey(destObjectKey); + request.setByteRangeStart(rangeStart); + request.setByteRangeEnd(rangeEnd); + request.setPartNumber(partNumber); + CopyPartResult result; + try { + result = obsClient.copyPart(request); + System.out.println("Part#" + partNumber + " done\n"); + partEtags.add(new PartEtag(result.getEtag(), result.getPartNumber())); + } catch (ObsException e) { + e.printStackTrace(); + } + } + }); + } + // Wait until the copy is complete. + executorService.shutdown(); + while (!executorService.isTerminated()) { + try { + executorService.awaitTermination(5, TimeUnit.SECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // Assemble parts. + CompleteMultipartUploadRequest completeMultipartUploadRequest = + new CompleteMultipartUploadRequest(destBucketName, destObjectKey, uploadId, partEtags); + obsClient.completeMultipartUpload(completeMultipartUploadRequest); + System.out.println("copyObject successfully"); + } catch (ObsException e) { + System.out.println("copyObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("copyObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
ObsClient allows you to create a URL with Query parameters that carry authentication information by specifying the AK and SK, HTTP method, and request parameters. You can provide this URL to other users for them to make a temporary access. When generating a URL, you need to specify the validity period of the URL to restrict the access duration of visitors.
+If you want to grant other users the permission to perform operations on buckets or objects (for example, upload or download objects), you need to generate a URL for the corresponding request (for example, a URL with the PUT request for uploading an object) and provide the URL to other users.
+The following table lists operations that can be performed through a signed URL.
+ +Operation + |
+HTTP Request Method (Value in OBS SDK for Java) + |
+Special Operator (Value in OBS SDK for Java) + |
+Bucket Name Required (Yes/No) + |
+Object Name Required (Yes/No) + |
+
|---|---|---|---|---|
Create Bucket + |
+HttpMethodEnum.PUT + |
+N/A + |
+Yes + |
+No + |
+
List Buckets + |
+HttpMethodEnum.GET + |
+N/A + |
+No + |
+No + |
+
Delete Bucket + |
+HttpMethodEnum.DELETE + |
+N/A + |
+Yes + |
+No + |
+
List Objects + |
+HttpMethodEnum.GET + |
+N/A + |
+Yes + |
+No + |
+
List Object Versions + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.VERSIONS + |
+Yes + |
+No + |
+
List Multipart Uploads + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.UPLOADS + |
+Yes + |
+No + |
+
Get Bucket Metadata + |
+HttpMethodEnum.HEAD + |
+N/A + |
+Yes + |
+No + |
+
Get Bucket Location + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.LOCATION + |
+Yes + |
+No + |
+
Get Bucket Storageinfo + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.STORAGEINFO + |
+Yes + |
+No + |
+
Set Bucket Quota + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.QUOTA + |
+Yes + |
+No + |
+
Get Bucket Quota + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.QUOTA + |
+Yes + |
+No + |
+
Set Bucket Storage Policy + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.STORAGEPOLICY + |
+Yes + |
+No + |
+
Get Bucket Storage Policy + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.STORAGEPOLICY + |
+Yes + |
+No + |
+
Configure Bucket ACL + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.ACL + |
+Yes + |
+No + |
+
Obtain Bucket ACL + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.ACL + |
+Yes + |
+No + |
+
Set Bucket Logging + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.LOGGING + |
+Yes + |
+No + |
+
Get Bucket Logging + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.LOGGING + |
+Yes + |
+No + |
+
Set Bucket Policy + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.POLICY + |
+Yes + |
+No + |
+
Get Bucket Policy + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.POLICY + |
+Yes + |
+No + |
+
Delete Bucket Policy + |
+HttpMethodEnum.DELETE + |
+SpecialParamEnum.POLICY + |
+Yes + |
+No + |
+
Set Lifecycle Rule + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.LIFECYCLE + |
+Yes + |
+No + |
+
Get Lifecycle Rule + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.LIFECYCLE + |
+Yes + |
+No + |
+
Delete Lifecycle Rule + |
+HttpMethodEnum.DELETE + |
+SpecialParamEnum.LIFECYCLE + |
+Yes + |
+No + |
+
Set Website Hosting + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.WEBSITE + |
+Yes + |
+No + |
+
Get Website Hosting + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.WEBSITE + |
+Yes + |
+No + |
+
Delete Website Hosting + |
+HttpMethodEnum.DELETE + |
+SpecialParamEnum.WEBSITE + |
+Yes + |
+No + |
+
Set Bucket Versioning + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.VERSIONING + |
+Yes + |
+No + |
+
Get Bucket Versioning + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.VERSIONING + |
+Yes + |
+No + |
+
Set CORS Rule + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.CORS + |
+Yes + |
+No + |
+
Get CORS Rule + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.CORS + |
+Yes + |
+No + |
+
Delete CORS Rule + |
+HttpMethodEnum.DELETE + |
+SpecialParamEnum.CORS + |
+Yes + |
+No + |
+
Set Bucket Tagging + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.TAGGING + |
+Yes + |
+No + |
+
Get Bucket Tagging + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.TAGGING + |
+Yes + |
+No + |
+
Delete Bucket Tagging + |
+HttpMethodEnum.DELETE + |
+SpecialParamEnum.TAGGING + |
+Yes + |
+No + |
+
Upload Object + |
+HttpMethodEnum.PUT + |
+N/A + |
+Yes + |
+Yes + |
+
Append Object + |
+HttpMethodEnum.POST + |
+SpecialParamEnum.APPEND + |
+Yes + |
+Yes + |
+
Get Object + |
+HttpMethodEnum.GET + |
+N/A + |
+Yes + |
+Yes + |
+
Copy Object + |
+HttpMethodEnum.PUT + |
+N/A + |
+Yes + |
+Yes + |
+
Delete Object + |
+HttpMethodEnum.DELETE + |
+N/A + |
+Yes + |
+Yes + |
+
Delete Objects + |
+HttpMethodEnum.POST + |
+SpecialParamEnum.DELETE + |
+Yes + |
+Yes + |
+
Get Object Metadata + |
+HttpMethodEnum.HEAD + |
+N/A + |
+Yes + |
+Yes + |
+
Configure Object ACL + |
+HttpMethodEnum.PUT + |
+SpecialParamEnum.ACL + |
+Yes + |
+Yes + |
+
Obtain Object ACL + |
+HttpMethodEnum.GET + |
+SpecialParamEnum.ACL + |
+Yes + |
+Yes + |
+
Initiate Multipart Upload + |
+HttpMethodEnum.POST + |
+SpecialParamEnum.UPLOADS + |
+Yes + |
+Yes + |
+
Upload Part + |
+HttpMethodEnum.PUT + |
+N/A + |
+Yes + |
+Yes + |
+
Copy Part + |
+HttpMethodEnum.PUT + |
+N/A + |
+Yes + |
+Yes + |
+
List Parts + |
+HttpMethodEnum.GET + |
+N/A + |
+Yes + |
+Yes + |
+
Assemble Parts + |
+HttpMethodEnum.POST + |
+N/A + |
+Yes + |
+Yes + |
+
Delete Multipart Upload + |
+HttpMethodEnum.DELETE + |
+N/A + |
+Yes + |
+Yes + |
+
Restore Cold Objects + |
+HttpMethodEnum.POST + |
+SpecialParamEnum.RESTORE + |
+Yes + |
+Yes + |
+
To access OBS using a signed URL generated by the OBS SDK for Java, perform the following steps:
+obsClient.createTemporarySignature(TemporarySignatureRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for creating a signed URL. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+No + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+No + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
specialParam + |
++ | +No + |
+Explanation: +Special parameters that may be used in the request, indicating the sub-operations. +Value range: +See Table 1. +Default value: +None + |
+
method + |
++ | +Yes + |
+Explanation: +HTTP method type. +Value range: +See Table 1. +Default value: +None + |
+
headers + |
+Map<String, String> + |
+No + |
+Explanation: +Headers in the request. In Map, the String key and value indicate the name and value of the request header respectively. +Default value: +None + |
+
queryParams + |
+Map<String, Object> + |
+No + |
+Explanation: +Query parameters in the request. In Map, the String key indicates the name of the query parameter, and the Object value indicates the value of the query parameter. +Default value: +None + |
+
expires + |
+long + |
+Yes + |
+Explanation: +Expiration time of the signed URL. +Value range: +
Default value: +300 + |
+
requestDate + |
+Date + |
+Yes + |
+Explanation: +Time when the request is initiated. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
signedUrl + |
+String + |
+Explanation: +The signed URL that carries the authentication information. +Default value: +None + |
+
actualSignedRequestHeaders + |
+Map<String, String> + |
+Explanation: +Actual headers in the request initiated using the signed URL. In Map, the String key and value indicate the name and value of the request header respectively. +Default value: +None + |
+
This example uses HttpMethodEnum.PUT to create bucket examplebucket based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import java.util.Map; +public class CreateBucket001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.PUT, expireSeconds); + request.setBucketName("examplebucket"); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Creating bucket using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a PUT request to create a bucket. + String location = "your bucket location"; + Request httpRequest = + builder.url(response.getSignedUrl()) + .put( + RequestBody.create( + null, + ("<CreateBucketConfiguration><Location>" + + location + + "</Location></CreateBucketConfiguration>").getBytes())) + .build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("\tStatus:" + res.code()); + if (res.body() != null) { + System.out.println("\tContent:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("CreateBucket successfully"); + } catch (ObsException e) { + System.out.println("CreateBucket failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("CreateBucket failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.PUT to upload object objectname to bucket examplebucket based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import java.util.HashMap; +import java.util.Map; +public class PutObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + Map<String, String> headers = new HashMap<>(); + String contentType = "text/plain"; + headers.put("Content-Type", contentType); + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.PUT, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setHeaders(headers); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Creating object using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a PUT request to upload an object. + Request httpRequest = + builder.url(response.getSignedUrl()) + .put(RequestBody.create(MediaType.parse(contentType), "Hello OBS".getBytes("UTF-8"))) + .build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + if (res.body() != null) { + System.out.println("Content:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("PutObject successfully"); + } catch (ObsException e) { + System.out.println("PutObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("PutObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.GET to download object objectname from bucket examplebucket based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import java.io.InputStream; +import java.util.Map; +public class GetObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Getting object using temporary signature url:"); + System.out.println("SignedUrl:" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a GET request to download an object. + Request httpRequest = builder.url(response.getSignedUrl()).get().build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + InputStream objectContent = null; + if (res.body() != null) { + objectContent = res.body().byteStream(); + System.out.println("Content:" + res.body().string() + "\n"); + } + if(objectContent != null) { + // objectContent is the file stream to download. + // You can read the objectContent stream to download the file. If the stream is not read for a long time, it will be disconnected from the server. + } + res.close(); + System.out.println("getObject successfully"); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.GET to list object in bucket examplebucket based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import java.util.Map; +public class ListObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds); + request.setBucketName("examplebucket"); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Getting object list using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a GET request to obtain the object list. + Request httpRequest = builder.url(response.getSignedUrl()).get().build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + if (res.body() != null) { + System.out.println("Content:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("ListObject successfully"); + } catch (ObsException e) { + System.out.println("ListObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("ListObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.DELETE to delete object objectname from bucket examplebucket based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import java.util.Map; +public class DeleteObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.DELETE, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Deleting object using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a DELETE request to delete an object. + Request httpRequest = builder.url(response.getSignedUrl()).delete().build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("\tStatus:" + res.code()); + if (res.body() != null) { + System.out.println("\tContent:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("deleteObjects successfully"); + } catch (ObsException e) { + System.out.println("deleteObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.POST to initiate a multipart upload based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.SpecialParamEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import java.util.Map; +public class InitiateMultiPartUpload001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.POST, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + request.setSpecialParam(SpecialParamEnum.UPLOADS); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("initiate multipart upload using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a POST request to initiate the multipart upload. + Request httpRequest = builder.url(response.getSignedUrl()).post(RequestBody.create(null, "")).build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + if (res.body() != null) { + System.out.println("Content:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("InitiateMultiPartUpload successfully"); + } catch (ObsException e) { + System.out.println("InitiateMultiPartUpload failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("InitiateMultiPartUpload failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.PUT to upload a part based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import java.util.HashMap; +import java.util.Map; +public class UploadPart001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.PUT, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + Map<String, Object> queryParams = new HashMap<String, Object>(); + // Set the partNumber parameter, for example, queryParams.put("partNumber", "1"). + queryParams.put("partNumber", "partNumber"); + queryParams.put("uploadId", "your uploadId"); + request.setQueryParams(queryParams); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("upload part using temporary signature url:"); + System.out.println("SignedUrl:" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a PUT request to upload a part. + Request httpRequest = + builder.url(response.getSignedUrl()) + .put(RequestBody.create(null, new byte[6 * 1024 * 1024])) + .build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + if (res.body() != null) { + System.out.println("Content:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("UploadPart successfully"); + } catch (ObsException e) { + System.out.println("UploadPart failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("UploadPart failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.PUT to list uploaded parts based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import java.util.HashMap; +import java.util.Map; +public class ListUploadedParts001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + Map<String, Object> queryParams = new HashMap<String, Object>(); + queryParams.put("uploadId", "your uploadId"); + request.setQueryParams(queryParams); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("list parts using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a GET request to list uploaded parts. + Request httpRequest = builder.url(response.getSignedUrl()).get().build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + if (res.body() != null) { + System.out.println("Content:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("ListParts successfully"); + } catch (ObsException e) { + System.out.println("ListParts failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("ListParts failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.POST to assemble parts based on a signed URL. The validity period of the URL is 3,600 seconds.
+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 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import java.util.HashMap; +import java.util.Map; +public class CompleteMultiPartUpload001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.POST, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + Map<String, String> headers = new HashMap<>(); + String contentType = "application/xml"; + headers.put("Content-Type", contentType); + request.setHeaders(headers); + Map<String, Object> queryParams = new HashMap<>(); + queryParams.put("uploadId", "your uploadId"); + request.setQueryParams(queryParams); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("complete multipart upload using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // The following content is used as an example. You need to replace it with the responses of the request for listing uploaded parts. + String content = "<CompleteMultipartUpload>"; + content += "<Part>"; + content += "<PartNumber>1</PartNumber>"; + content += "<ETag>da6a0d097e307ac52ed9b4ad551801fc</ETag>"; + content += "</Part>"; + content += "<Part>"; + content += "<PartNumber>2</PartNumber>"; + content += "<ETag>da6a0d097e307ac52ed9b4ad551801fc</ETag>"; + content += "</Part>"; + content += "</CompleteMultipartUpload>"; + // Make a POST request to assemble the uploaded parts. + Request httpRequest = + builder.url(response.getSignedUrl()) + .post(RequestBody.create(MediaType.parse(contentType), content.getBytes("UTF-8"))) + .build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("\tStatus:" + res.code()); + if (res.body() != null) { + System.out.println("\tContent:" + res.body().string() + "\n"); + } + res.close(); + } catch (ObsException e) { + System.out.println("CompleteMultiPartUpload failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("CompleteMultiPartUpload failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses HttpMethodEnum.GET to download an object encrypted using SSE-C. The validity period of the URL is 3,600 seconds.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.HttpMethodEnum; +import com.obs.services.model.TemporarySignatureRequest; +import com.obs.services.model.TemporarySignatureResponse; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import java.util.HashMap; +import java.util.Map; +public class GetObject003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Download an object encrypted using SSE-C. + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds); + request.setBucketName("examplebucket"); + request.setObjectKey("objectname"); + // Set the encryption method to SSE-C. + Map<String, String> headers = new HashMap<>(); + headers.put("x-obs-server-side-encryption-customer-algorithm", "AES256"); + // Set the key used for encryption, which is a Base64-encoded 256-bit value. + headers.put( + "x-obs-server-side-encryption-customer-key", + "your base64 sse-c key generated by AES-256 algorithm"); + // Set the MD5 value of the key used for encryption, which is a Base64-encoded, 128-bit MD5 value. + headers.put("x-obs-server-side-encryption-customer-key-MD5", "the md5 value of your sse-c key"); + request.setHeaders(headers); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Getting object using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a GET request to download an object. + Request httpRequest = builder.url(response.getSignedUrl()).get().build(); + OkHttpClient httpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .retryOnConnectionFailure(false) + .cache(null) + .build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("Status:" + res.code()); + if (res.body() != null) { + System.out.println("Content:" + res.body().string() + "\n"); + } + res.close(); + System.out.println("getObject successfully"); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uses content-md5 for integrity check when using a temporary URL to upload an object to OBS.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 | import com.obs.services.ObsClient; +import com.obs.services.internal.utils.ServiceUtils; +import com.obs.services.model.*; +import okhttp3.*; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Map; +public class Create_TemporarySignature_Uploadobject { + public static void main(String[] args) throws IOException, NoSuchAlgorithmException { +// Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + // Create an instance of ObsClient. + // Use a permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use a temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + // Set the validity period of the URL to 3600 seconds. + long expireSeconds = 3600L; + Map<String, String> headers = new HashMap<String, String>(); + String localFile_path = "localFile_path"; + //Convert the local file into a stream and calculate its MD5 value. + try (FileInputStream fileInputStream = new FileInputStream(localFile_path)) { + String md5 = ServiceUtils.toBase64(ServiceUtils.computeMD5Hash(fileInputStream)); + headers.put("content-md5",md5); + } + TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.PUT, expireSeconds); + request.setBucketName("your_bucketname"); + request.setObjectKey("objectkey"); + request.setHeaders(headers); + TemporarySignatureResponse response = obsClient.createTemporarySignature(request); + System.out.println("Creating object using temporary signature url:"); + System.out.println("\t" + response.getSignedUrl()); + Request.Builder builder = new Request.Builder(); + for (Map.Entry<String, String> entry : response.getActualSignedRequestHeaders().entrySet()) { + builder.header(entry.getKey(), entry.getValue()); + } + // Make a PUT request to upload the file. + Request httpRequest = builder.url(response.getSignedUrl()) + .put(RequestBody.create(getBytesByFile(localFile_path))).build(); + OkHttpClient httpClient = new OkHttpClient.Builder().followRedirects(false).retryOnConnectionFailure(false) + .cache(null).build(); + Call c = httpClient.newCall(httpRequest); + Response res = c.execute(); + System.out.println("\tStatus:" + res.code()); + if (res.body() != null) { + System.out.println("\tContent:" + res.body().string() + "\n"); + } + res.close(); + } + public static byte[] getBytesByFile(String pathStr) { + File file = new File(pathStr); + try (FileInputStream fis = new FileInputStream(file); + ByteArrayOutputStream bos = new ByteArrayOutputStream(1000)) { + byte[] b = new byte[1000]; + int n; + while ((n = fis.read(b)) != -1) { + bos.write(b, 0, n); + } + return bos.toByteArray(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} + |
You can use versioning to store multiple versions of an object in a bucket.
+When versioning is enabled for a bucket, OBS keeps multiple versions of an object in the bucket, allowing you to easily retrieve and restore historical versions or recover data in the event of accidental changes or application failures.
+By default, versioning is disabled for new OBS buckets. In this case, if a newly uploaded object is using the name of the previously uploaded one, the new object will overwrite the previous one.
+For details about different versioning operations, see:
+ + +You can enable versioning to automatically maintain previous versions of an object. When versioning is enabled, you can access earlier versions of an object to recover your data in the event of accidental actions or application failures.
+This API configures the versioning status for a bucket.
+obsClient.setBucketVersioning(final SetBucketVersioningRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for bucket versioning configuration. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
status + |
++ | +Yes + |
+Explanation: +Versioning status of the bucket. +Value range: +See Table 3. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
SUSPENDED + |
+Suspended + |
+Versioning is suspended. + |
+
ENABLED + |
+Enabled + |
+Versioning is enabled. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example enables and suspends versioning of bucket examplebucket.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketVersioningConfiguration; +import com.obs.services.model.VersioningStatusEnum; +public class SetBucketVersioning001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Enable versioning. + obsClient.setBucketVersioning( + "examplebucket", new BucketVersioningConfiguration(VersioningStatusEnum.ENABLED)); + // Suspend versioning. + obsClient.setBucketVersioning( + "examplebucket", new BucketVersioningConfiguration(VersioningStatusEnum.SUSPENDED)); + System.out.println("setBucketVersioning successfully"); + } catch (ObsException e) { + System.out.println("setBucketVersioning failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketVersioning failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can enable versioning to automatically maintain previous versions of an object. When versioning is enabled, you can access earlier versions of an object to recover your data in the event of accidental actions or application failures.
+This API obtains the versioning status of a bucket.
+obsClient.getBucketVersioning(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for viewing the versioning status of a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
status + |
++ | +Explanation: +Versioning status of the bucket. +Value range: +See Table 4. + |
+
This example views the versioning status of bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketVersioningConfiguration; +public class GetBucketVersioning001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // View the versioning status of a bucket. + BucketVersioningConfiguration status = obsClient.getBucketVersioning("examplebucket"); + System.out.println("getBucketVersioning successfully"); + System.out.println("getVersioningStatus:" + status.getVersioningStatus()); + } catch (ObsException e) { + System.out.println("getBucketVersioning failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getBucketVersioning failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can call ObsClient.getObject to obtain an object version by specifying the version ID (versionId).
+obsClient.getObject(GetObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for downloading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. If version ID is left blank, the latest version of the object will be downloaded. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
rangeStart + |
+Long + |
+No + |
+Explanation: +Start position for object download. +Value range: +A non-negative integer. +Default value: +None + |
+
rangeEnd + |
+Long + |
+No + |
+Explanation: +End position for object download. +Restrictions: +The upper limit of the value is the object length minus 1, in bytes. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is the same as the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is different from the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
IfUnmodifiedSince + |
+Date + |
+No + |
+Explanation: +The object is returned if it has not been modified since the specified time; otherwise, an error is returned. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side decryption header. For details, see Table 7. + |
+
replaceMetadata + |
++ | +No + |
+Explanation: +Additional information about the object. For details, see Table 3. + |
+
progressListener + |
++ | +No + |
+Explanation: +Data transmission listener for obtaining the download progress. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object in a download. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 6. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 8. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the file data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 11. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 10. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 12. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
This example sets the version ID to obtain object versions and views the versioning status of object objectname in bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsObject; +public class GetObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the version ID to obtain object versions. + ObsObject obsObject = obsClient.getObject("examplebucket", "objectname", "versionid1"); + System.out.println("getObject successfully"); + obsObject.getObjectContent().close(); + } catch (ObsException e) { + System.out.println("getObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API copies an object version in a specified bucket.
+You can call ObsClient.copyObject to copy an object version by specifying the version ID (versionId).
+obsClient.copyObject(CopyObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for copying an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Target bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Target object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header used for encrypting the target object. For details, see Table 3. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header used for encrypting the target object. For details, see Table 4. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +ACL that can be pre-defined during the object copy. For details, see Table 8. +Default value: +None + |
+
successRedirectLocation + |
+String + |
+No + |
+Explanation: +Address (URL) to which a successfully answered request is redirected. +
Default value: +None + |
+
sourceBucketName + |
+String + |
+Yes + |
+Explanation: +Name of the source bucket. +Restrictions: +
Default value: +None + |
+
sourceObjectKey + |
+String + |
+Yes + |
+Explanation: +Source object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
newObjectMetadata + |
++ | +No + |
+Explanation: +User-defined metadata of the target object. For details, see Table 15. +Restrictions: +newObjectMetadata must be used together with replaceMetadata. +Default value: +None + |
+
replaceMetadata + |
+boolean + |
+No + |
+Explanation: +Whether to rewrite the metadata of the source object. +Restrictions: +replaceMetadata must be used together with newObjectMetadata. +Value range: +true: The metadata of the source object is rewritten. +false: The metadata of the source object is not rewritten. +Default value: +None + |
+
ifModifiedSince + |
+java.util.Date + |
+No + |
+Explanation: +The source object is copied if it has been modified since the specified time; otherwise, an exception is thrown. +Default value: +None + |
+
ifUnmodifiedSince + |
+java.util.Date + |
+No + |
+Explanation: +If the source object has not been modified since the specified time, it is copied. Otherwise, an exception is thrown. +Default value: +None + |
+
ifMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is the same as the preset ETag, the object is returned. Otherwise, an error is returned. The ETag of the source object is the MD5 value of it. +Restrictions: +
Value range: +The value must contain 32 characters. +Default value: +None + |
+
ifNoneMatchTag + |
+String + |
+No + |
+Explanation: +Preset ETag. If the ETag of the object to be downloaded is different from the preset ETag, the object is returned. Otherwise, an error is returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Version ID of the source object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
sseCHeaderSource + |
++ | +No + |
+Explanation: +Server-side decryption header used for decrypting the source object. For details, see Table 4. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 5. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 6. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats:
+
Default value: +
|
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 7. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 6. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 9. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 10. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 12. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 11. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 13. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 14. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the file data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 16. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
lastModified + |
+java.util.Date + |
+Explanation: +Last time the target object was modified. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of the target object. Base64-encoded, 128-bit MD5 value of an object. ETag is the unique identifier of the object contents and is used to determine whether the contents of an object are changed. For example, if the ETag value is A when an object is uploaded and is B when the object is downloaded, this indicates the contents of the object are changed. The ETag reflects changes only to the contents of an object, not its metadata. Objects created by the upload and copy operations have unique ETags after being encrypted using MD5. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Version ID of the target object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
copySourceVersionId + |
+String + |
+Explanation: +Version ID of the source object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of the target object. +Value range: +See Table 16. +Default value: +None + |
+
This example sets a version ID to copy object versions of sourceobjectname from bucket sourceexamplebucket to another bucket.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.CopyObjectRequest; +public class CopyObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Copy object versions. + CopyObjectRequest request = new CopyObjectRequest(); + request.setSourceBucketName("sourceexamplebucket"); + request.setSourceObjectKey("sourceobjectname"); + // Set the version ID of the object to be copied. + request.setVersionId("versionid"); + request.setDestinationBucketName("destexamplebucket"); + request.setDestinationObjectKey("destobjectname"); + obsClient.copyObject(request); + System.out.println("copyObject successfully"); + } catch (ObsException e) { + System.out.println("copyObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("copyObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API downloads a Cold object. To download such an object, you must restore it first. For the options for the restore speed, see Table 3.
+You can call ObsClient.restoreObject to restore a Cold object version by specifying the versionId.
+obsClient.restoreObject(RestoreObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for restoring a Cold object version. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Version ID of the Cold object to restore. +Value range: +The value must contain 32 characters. +Default value: +None. If this parameter is left blank, the latest version of the object is specified. + |
+
days + |
+int + |
+Yes + |
+Explanation: +After an object is restored, a Standard copy is generated for the object. This parameter specifies how long the Standard copy can be retained, that is, the validity period of the restored object. +Restrictions: +The value must be a positive integer. +Value range: +The value ranges from 1 to 30, in days. +Default value: +None + |
+
tier + |
++ | +No + |
+Explanation: +The restore option, which indicates the time spent on restoring the object. +Value range: +For details, see Table 3. +Default value: +Standard + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example restores object version objectname in bucket examplebucket at an expedited speed and retains the restored object for one day.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsObject; +import com.obs.services.model.RestoreObjectRequest; +import com.obs.services.model.RestoreTierEnum; +public class RestoreObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Restore an object version at an expedited speed. + RestoreObjectRequest request = new RestoreObjectRequest("examplebucket", "objectname", 1); + request.setRestoreTier(RestoreTierEnum.EXPEDITED); + request.setVersionId("versionid"); + obsClient.restoreObject(request); + System.out.println("RestoreObject successfully"); + } catch (ObsException e) { + System.out.println("RestoreObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("RestoreObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API lists some or all of the object versions in a bucket. When listing the object versions, you can specify the criteria such as the prefix, number, and start position. Returned object versions are listed in alphabetical order by object name.
+The returned results of ObsClient.listVersions include the object versions and delete markers.
+obsClient.listVersions(ListVersionsRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for listing object versions in a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
prefix + |
+String + |
+No + |
+Explanation: +Prefix that the names of objects to list must contain. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
keyMarker + |
+String + |
+No + |
+Explanation: +Object name to start with when listing object versions in a bucket. All object versions following this parameter are listed in alphabetical order. +Restrictions: +This parameter is only available for listing objects with multiple versions. +Value range: +The value of nextKeyMarker in the response body of the last request. +Default value: +None + |
+
maxKeys + |
+int + |
+No + |
+Explanation: +The maximum number of object versions returned in the response in alphabetical order. +Value range: +The value ranges from 1 to 1000. If the specified value is beyond this range, only 1,000 objects are returned. +Default value: +1000 + |
+
delimiter + |
+String + |
+No + |
+Explanation: +This parameter is used to group object names. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one CommonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one CommonPrefixes. +Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, objects abcd and abcde are grouped into a commonPrefix with abcd as the prefix. If only delimiter is set to d, objects abcd and abcde are grouped into a commonPrefix with abcd as the prefix, and bbcde is grouped separately into another commonPrefix with bbcd as the prefix. +For a PFS, if this parameter is not specified, all the contents in the current directory are recursively listed by default, and subdirectories are also listed. In big data scenarios, PFSs usually have multiple directory levels and each directory level has a large number of files. In such case, you are advised to configure [delimiter=/] to list the contents in the current directory but exclude the contents in subdirectories, thereby accelerating the listing. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionIdMarker + |
+String + |
+No + |
+Explanation: +Version ID you want to start listing from. All object versions following the value specified by this parameter are listed in alphabetical order by object name and version ID. This parameter must be used together with keyMarker. keyMarker specifies the object name, and versionIdMarker specifies the version of the specified object. +Restrictions: +
Value range: +Object version ID, that is, the value of nextVersionIdMarker in the response body of the last request. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
prefix + |
+String + |
+Explanation: +Object name prefix. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you specify logs/ as the prefix, logs/day1, logs/day2, and logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all objects in the bucket will be returned. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionIdMarker + |
+String + |
+Explanation: +Object version for the object specified by KeyMarker. All object versions following the value specified by this parameter are listed in alphabetical order by object name and version ID. This parameter must be used together with KeyMarker. KeyMarker specifies the object name, and versionIdMarker specifies the version of the specified object. +Restrictions: +
Value range: +The value must contain 32 characters. +Default value: +None + |
+
nextVersionIdMarker + |
+String + |
+Explanation: +Version ID to start with in the next request for listing object versions. It must be used together with nextKeyMarker. If only part of the object versions are returned for the current request, this parameter is included in the response for your use in the subsequent request. +Restrictions: +This parameter is only available for listing objects with multiple versions. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectSummaries + |
+List<ObsObject> + |
+Explanation: +Object information. For details, see Table 4. + |
+
commonPrefixes + |
+List<String> + |
+Explanation: +List of object name prefixes grouped according to the delimiter parameter (if specified) +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
truncated + |
+boolean + |
+Explanation: +Whether all objects are returned in the response. A maximum of 1,000 objects can be listed at a time. If the number of objects is greater than 1,000, the objects beyond 1,000 cannot be returned. +Value range: +true: Not all objects are returned. +false: All objects are returned. +Default value: +None + |
+
keyMarker + |
+String + |
+Explanation: +Object name to start listing from. All object versions following the value specified by this parameter are listed in alphabetical order by object name. +Restrictions: +This parameter is only available for listing objects with multiple versions. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
maxKeys + |
+int + |
+Explanation: +Maximum number of objects to list. No more than the specified number of objects can be returned in the response in alphabetical order. +Value range: +The value ranges from 1 to 1000. If the specified value is beyond this range, only 1,000 objects are returned. +Default value: +1000 + |
+
delimiter + |
+String + |
+Explanation: +Object names are grouped by this parameter, which is often used with Prefix. If a prefix is specified, objects with the same string from the prefix to the first delimiter are grouped into one CommonPrefixes. If no prefix is specified, objects with the same string from the first character to the first delimiter are grouped into one CommonPrefixes. +Assume that a bucket has objects abcd, abcde, and bbcde in it. If delimiter is set to d and prefix is set to a, files abcd and abcde are grouped into a CommonPrefixes with abcd as the prefix. If only delimiter is set to d, files abcd and abcde are grouped into a CommonPrefixes with abcd as the prefix, and bbcde is grouped separately into another CommonPrefixes with bbcd as the prefix. +For a PFS, if this parameter is not specified, all the contents in the current directory are recursively listed by default, and subdirectories are also listed. In big data scenarios, PFSs usually have multiple directory levels and each directory level has a large number of files. In such case, you are advised to configure [delimiter=/] to list the contents in the current directory but exclude the contents in subdirectories, thereby accelerating the listing. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
nextKeyMarker + |
+String + |
+Explanation: +Object name to start with for the next request for listing object versions. If only part of the object versions are returned for the current request, this parameter is included in the response for your use in the subsequent request. +Restrictions: +This parameter is only available for listing objects with multiple versions. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
location + |
+String + |
+Explanation: +Region where a bucket is located. +Value range: +To learn about valid regions and endpoints, see Regions and Endpoints. An endpoint is the request address for calling an API. Endpoints vary depending on services and regions. To obtain the regions and endpoints, contact the enterprise administrator. + |
+
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
versions + |
++ | +Explanation: +Object version information. For details, see Table 8. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
owner + |
++ | +Explanation: +Owner of the object. For details, see Table 5. + |
+
metadata + |
++ | +Explanation: +Object metadata. For details, see Table 6. + |
+
objectContent + |
+InputStream + |
+Explanation: +Object data stream. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the file data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 7. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
key + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
isLatest + |
+boolean + |
+Explanation: +Whether the object is the latest version. +Value range: +
Default value: +false + |
+
lastModified + |
+Date + |
+Explanation: +Time when the object was last modified. +Value range: +UTC time +Default value: +None + |
+
owner + |
++ | +Explanation: +User information, including the domain ID and name of the object owner. For details, see Table 5. + |
+
etag + |
+String + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. ETag is the unique identifier of the object contents and is used to determine whether the contents of an object are changed. For example, if the ETag value is A when an object is uploaded and is B when the object is downloaded, this indicates the contents of the object are changed. The ETag reflects changes only to the contents of an object, not its metadata. Objects created by the upload and copy operations have unique ETags after being encrypted using MD5. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
size + |
+long + |
+Explanation: +Object size, in bytes. +Value range: +The value ranges from 0 TB to 48.8 TB, in bytes. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 7. +Default value: +None + |
+
isDeleteMarker + |
+boolean + |
+Explanation: +Whether the object version is a delete marker. +Value range: +true +false +Default value: +None + |
+
This example lists object versions in bucket examplebucket. A maximum of 1,000 object versions can be returned.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Listing object versions. + ListVersionsResult result = obsClient.listVersions("examplebucket"); + System.out.println("listVersions successfully"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists a specified number of object versions in bucket examplebucket.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List a specified number of object versions. + ListVersionsResult result = obsClient.listVersions("examplebucket", 100); + System.out.println("listVersions successfully"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example specifies a prefix to list object versions in bucket examplebucket. A maximum of 100 object versions will be returned.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions003 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List object versions by specifying a prefix. + // List 100 object versions with the specified prefix. + ListVersionsRequest request = new ListVersionsRequest("examplebucket", 100); + request.setPrefix("prefix"); + ListVersionsResult result = obsClient.listVersions(request); + System.out.println("listVersions successfully"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists 100 object versions whose names follow test in lexicographical order in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List objects from a specified start position. + // List 100 object versions whose names following test in lexicographic order. + ListVersionsRequest request = new ListVersionsRequest("examplebucket", 100); + request.setKeyMarker("test"); + ListVersionsResult result = obsClient.listVersions(request); + System.out.println("listVersions successfully"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists 100 object versions whose names follow test in lexicographical order in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions005 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List all object versions using pagination. + ListVersionsResult result; + ListVersionsRequest request = new ListVersionsRequest("examplebucket", 100); + do { + result = obsClient.listVersions(request); + System.out.println("listVersions successfully"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + request.setKeyMarker(result.getNextKeyMarker()); + request.setVersionIdMarker(result.getNextVersionIdMarker()); + } while (result.isTruncated()); + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
There is no concept of folders in OBS. All elements stored in OBS buckets are objects. Folders are actually objects whose sizes are 0 and whose names end with a slash (/). You can set a folder name as a prefix to list objects in this folder. This example lists all object versions in a folder.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions006 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + //List all object versions in a folder. + ListVersionsResult result; + ListVersionsRequest request = new ListVersionsRequest("examplebucket", 100); + // Set folder name dir/ as the prefix. + request.setPrefix("dir/"); + do { + result = obsClient.listVersions(request); + System.out.println("listVersions successfully"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + request.setKeyMarker(result.getNextKeyMarker()); + request.setVersionIdMarker(result.getNextVersionIdMarker()); + } while (result.isTruncated()); + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example lists all object versions in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ListVersionsRequest; +import com.obs.services.model.ListVersionsResult; +import com.obs.services.model.VersionOrDeleteMarker; +public class ListVersions007 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // List all object versions in the root directory. + ListVersionsRequest request = new ListVersionsRequest("examplebucket", 1000); + request.setDelimiter("/"); + ListVersionsResult result = obsClient.listVersions(request); + System.out.println("listVersions successfully"); + System.out.println("Objects in the root directory:"); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + listVersionsByPrefix(obsClient, result); + } catch (ObsException e) { + System.out.println("listVersions failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("listVersions failed"); + // Print other error information. + e.printStackTrace(); + } + } + |
This example recursively lists object versions in a sub-folder.
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 | // Recursively list object versions in a sub-folder. + static void listVersionsByPrefix(ObsClient obsClient, ListVersionsResult result) throws ObsException { + for (String prefix : result.getCommonPrefixes()) { + System.out.println("Objects in folder [" + prefix + "]:"); + ListVersionsRequest request = new ListVersionsRequest("examplebucket", 1000); + request.setDelimiter("/"); + request.setPrefix(prefix); + result = obsClient.listVersions(request); + for (VersionOrDeleteMarker v : result.getVersions()) { + System.out.println("Key:" + v.getKey()); + System.out.println("Owner:" + v.getOwner()); + System.out.println("isDeleteMarker:" + v.isDeleteMarker()); + } + listVersionsByPrefix(obsClient, result); + } + } +} + |
OBS allows the control of access permissions for objects. By default, only object creators have the read and write permissions on the object. You can set access control policies for objects. For example, if an object is configured with the public access policy, all users are allowed to read the object. If an object is encrypted with SSE-KMS, the ACL configured for it is not in effect in the cross-tenant case.
+You can set an ACL when uploading an object or call an ACL API to modify or obtain the ACL of an existing object.
+obsClient.setObjectAcl(SetObjectAclRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for setting an object ACL. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL specified for the object. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 4. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 6. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 9. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 7. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 8. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example sets an ACL for the versioned object objectname in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.GroupGrantee; +import com.obs.services.model.Owner; +import com.obs.services.model.Permission; +public class SetObjectAcl001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Define the ACL of the versioned object to Private. + obsClient.setObjectAcl("examplebucket", "objectname", AccessControlList.REST_CANNED_PRIVATE, "versionid"); + AccessControlList acl = new AccessControlList(); + Owner owner = new Owner(); + owner.setId("ownerid"); + acl.setOwner(owner); + // Grant the read permission to all users. + acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ); + // Set the ACL for the versioned object. + obsClient.setObjectAcl("examplebucket", "objectname", acl, "versionid"); + System.out.println("setObjectAcl successfully"); + } catch (ObsException e) { + System.out.println("setObjectAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setObjectAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The owner or grantee ID needed in the ACL indicates the account ID, which can be viewed on the My Credential page of OBS Console.
+This API deletes an object from a specific bucket.
+You can call ObsClient.deleteObject to pass a version ID (versionId) to delete an object version.
+obsClient.deleteObject(DeleteObjectRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for deleting an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
deleteMarker + |
+boolean + |
+Explanation: +Whether the deleted object is a delete marker. +Value range: +
Default value: +false + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
This example passes a version ID (versionId) to delete an object version using ObsClient.deleteObject.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete the object version. + obsClient.deleteObject("examplebucket", "objectname", "versionid"); + System.out.println("deleteObject successfully"); + } catch (ObsException e) { + System.out.println("deleteObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS allows the control of access permissions for objects. By default, only object creators have the read and write permissions on the object. You can call an ACL API to modify or obtain the ACL of an existing object.
+This API returns the ACL for a specific object version in a bucket.
+obsClient.getObjectAcl(GetObjectAclRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for obtaining the ACL of the object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+Yes + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 4. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 6. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 9. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 7. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 8. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
This example returns the ACL information of object version objectname in bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +public class GetObjectAcl001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain the ACL of the versioned object. + AccessControlList acl = obsClient.getObjectAcl("examplebucket", "objectname", "versionid"); + System.out.println("getObjectAcl successfully"); + System.out.println(acl); + } catch (ObsException e) { + System.out.println("getObjectAcl failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectAcl failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API deletes objects in batches from a specific bucket. Deleted objects cannot be recovered.
+In a batch delete operation, OBS concurrently deletes the specified objects and returns the deletion result of each object.
+You can call ObsClient.deleteObjects to pass version IDs (versionId) to delete object versions.
+obsClient.deleteObjects(DeleteObjectsRequest deleteRequest)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
deleteRequest + |
++ | +Yes + |
+Explanation: +Request parameters for deleting objects in batches. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
keyAndVersions + |
+List<KeyAndVersion> + |
+Yes + |
+Explanation: +List of objects to be deleted. For details, see Table 3. + |
+
quiet + |
+boolean + |
+No + |
+Explanation: +Response mode to the request for deleting objects in a batch. +Value range: +
Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
key + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None. If this parameter is left blank, the latest version of the object is deleted. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
deletedObjectResults + |
+List<DeleteObjectResult> + |
+Explanation: +Response results of the request for deleting objects in a batch. For details, see Table 5. + |
+
errorResults + |
+List<ErrorResult> + |
+Explanation: +List of objects that fail to be deleted. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
deleteMarker + |
+boolean + |
+Explanation: +Whether the deleted object is a delete marker. +Value range: +
Default value: +false + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
versionId + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
errorCode + |
+String + |
+Explanation: +Error code for the failed deletion. + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
message + |
+String + |
+Explanation: +Error message for the failed deletion. + |
+
This example passes multiple version IDs (versionId) to batch delete object versions using ObsClient.deleteObjects.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.DeleteObjectsRequest; +import com.obs.services.model.DeleteObjectsResult; +import com.obs.services.model.KeyAndVersion; +import java.util.ArrayList; +import java.util.List; +public class DeleteObjects001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete object versions in a batch. + DeleteObjectsRequest request = new DeleteObjectsRequest("examplebucket"); + request.setQuiet(false); + List<KeyAndVersion> toDelete = new ArrayList<KeyAndVersion>(); + toDelete.add(new KeyAndVersion("objectname1", "versionid1")); + toDelete.add(new KeyAndVersion("objectname2", "versionid2")); + toDelete.add(new KeyAndVersion("objectname3", "versionid3")); + request.setKeyAndVersions(toDelete.toArray(new KeyAndVersion[toDelete.size()])); + DeleteObjectsResult result = obsClient.deleteObjects(request); + System.out.println("deleteObjects successfully"); + System.out.println("getDeletedObjectResults:" + result.getDeletedObjectResults()); + System.out.println("getErrorResults:" + result.getErrorResults()); + } catch (ObsException e) { + System.out.println("deleteObjects failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteObjects failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS allows you to set lifecycle rules for buckets to automatically transition the storage class of an object or delete expired objects, to effectively use storage features and optimize the storage space. You can set multiple lifecycle rules based on the prefix. A lifecycle rule must contain:
+This API configures lifecycle rules for a bucket to periodically delete objects in the bucket or transition objects between storage classes.
+
obsClient.setBucketLifecycle(final SetBucketLifecycleRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
deleteRequest + |
++ | +Yes + |
+Explanation: +Request parameters for setting the lifecycle rule. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
lifecycleConfig + |
++ | +Yes + |
+Explanation: +Lifecycle rules for the bucket. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
rules + |
+List<Rule> + |
+No + |
+Explanation: +List of lifecycle rules. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+No + |
+Explanation: +Lifecycle rule ID. +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
prefix + |
+String + |
+Yes + |
+Explanation: +Object name prefix. It identifies the objects the rule applies to. You can leave this parameter blank to apply the rule to all objects in the bucket. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you set prefix to ExampleObject.jpg, the rule applies to object ExampleObject.jpg only. If you set prefix to logs/, the rule applies to the three objects with name starting with logs/. If you leave prefix blank, the rule applies to all objects in the bucket. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
enabled + |
+boolean + |
+Yes + |
+Explanation: +Whether to enable the rule. +Value range: +true: The rule is enabled. +false: The rule is disabled. +Default value: +None + |
+
expiration + |
++ | +No + |
+Explanation: +Expiration time of an object. For details, see Table 5. +Default value: +None + |
+
noncurrentVersionExpiration + |
++ | +No + |
+Explanation: +Expiration time of noncurrent object versions. For details, see Table 6. +Restrictions: +
Default value: +None + |
+
transitions + |
+List<Transition> + |
+No + |
+Explanation: +Policies for storage class transition, including transition time and the storage class after transition. For details, see Table 7. +Restrictions: +This parameter is only available for the current object version. +Default value: +None + |
+
noncurrentVersionTransitions + |
++ | +No + |
+Explanation: +Policies for storage class transition of noncurrent versions, including transition time and the storage class after transition. For details, see Table 9. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+Yes if date is absent during object storage class transition +Yes if date or expiredObjectDeleteMarker is absent during object deletion + |
+Explanation: +Number of days (since the last update was made to the object) after which the lifecycle rule takes effect (the object will be deleted). +Restrictions: +This parameter is only available for the current object version. +Value range: +A positive integer, in days. +Default value: +None + |
+
date + |
+Date + |
+Yes if days is absent during object storage class transition. +Yes if days or expiredObjectDeleteMarker is absent during object deletion + |
+Explanation: +The value must conform to the ISO8601 standards and indicate UTC 00:00. For example, 2018-01-01T00:00:00.000Z indicates only objects that were last modified before the specified time are transitioned to the specified storage class or deleted. +Default value: +None + |
+
expiredObjectDeleteMarker + |
+Boolean + |
+Yes if days or date is absent + |
+Explanation: +Whether to delete expired delete markers. The value can be true or false. If tags are configured in a lifecycle rule, this element cannot be configured. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+Yes + |
+Explanation: +Number of days an object is noncurrent before it expires. +Restrictions: +This parameter is only available for noncurrent object versions. +Value range: +A positive integer, in days. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+This parameter is mandatory if date is not configured. + |
+Explanation: +Number of days after its creation when the object is transitioned. +Restrictions: +This parameter is only available for the current object version. +Value range: +A positive integer, in days. +Default value: +None + |
+
date + |
+Date + |
+This parameter is mandatory if days is not configured. + |
+Explanation: +Date when the object will be transitioned. +Default value: +None + |
+
storageClass + |
++ | +Yes + |
+Explanation: +Storage class the object is transitioned to. +Restrictions: +Restrictions on storage class transitions:
+
Value range: +See Table 8. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+This parameter is mandatory if date is not configured. + |
+Explanation: +Number of days after its creation when the object is transitioned. +Restrictions: +This parameter is only available for noncurrent object versions. +Value range: +A positive integer, in days. +Default value: +None + |
+
storageClass + |
++ | +Yes + |
+Explanation: +Storage class the object is transitioned to. +Restrictions: +Restrictions on storage class transitions:
+
Value range: +See Table 8. +Default value: +None + |
+
Transitions, Expiration, NoncurrentVersionTransitions, AbortIncompleteMultipartUpload, and NoncurrentVersionExpiration must not be all left blank.
+Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures a transition policy for latest and historical object versions in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.LifecycleConfiguration; +import com.obs.services.model.StorageClassEnum; +public class SetBucketLifecycle001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + //Set an object transition policy. + LifecycleConfiguration config = new LifecycleConfiguration(); + LifecycleConfiguration.Rule rule = config.new Rule(); + rule.setEnabled(true); + rule.setId("rule1"); + rule.setPrefix("prefix"); + LifecycleConfiguration.Transition transition = config.new Transition(); + // Specify that objects whose names contain the specified prefix will be transitioned 30 days after creation. + transition.setDays(30); + // Specify the storage class that the object will be transitioned to. + transition.setObjectStorageClass(StorageClassEnum.WARM); + // Specify when the objects whose names contain the specified prefix will be transitioned. + // transition.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2018-10-31")); + rule.getTransitions().add(transition); + LifecycleConfiguration.NoncurrentVersionTransition noncurrentVersionTransition = + config.new NoncurrentVersionTransition(); + // Specify that objects whose names contain the specified prefix will be transitioned 30 days after being historical versions. + noncurrentVersionTransition.setDays(30); + // Specify the storage class of the historical object version after transition. + noncurrentVersionTransition.setObjectStorageClass(StorageClassEnum.COLD); + rule.getNoncurrentVersionTransitions().add(noncurrentVersionTransition); + // Set the expiration time of fragments. + LifecycleConfiguration.AbortIncompleteMultipartUpload abortIncompleteMultipartUpload = config.new AbortIncompleteMultipartUpload(); + abortIncompleteMultipartUpload.setDaysAfterInitiation(7); + rule.setAbortIncompleteMultipartUpload(abortIncompleteMultipartUpload); + config.addRule(rule); + obsClient.setBucketLifecycle("examplebucket", config); + System.out.println("setBucketLifecycle successfully"); + } catch (ObsException e) { + System.out.println("setBucketLifecycle failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketLifecycle failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example configures the expiration time of latest and historical object versions in bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.LifecycleConfiguration; +public class SetBucketLifecycle002 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Set the object expiration time. + LifecycleConfiguration config = new LifecycleConfiguration(); + LifecycleConfiguration.Rule rule = config.new Rule(); + rule.setEnabled(true); + rule.setId("rule1"); + rule.setPrefix("prefix"); + LifecycleConfiguration.Expiration expiration = config.new Expiration(); + // Specify that objects whose names contain the specified prefix will expire 60 days after creation. + expiration.setDays(60); + // Specify when the objects whose names contain the specified prefix will expire. + // expiration.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2018-12-31")); + rule.setExpiration(expiration); + LifecycleConfiguration.NoncurrentVersionExpiration noncurrentVersionExpiration = + config.new NoncurrentVersionExpiration(); + // Specify that objects whose names contain the specified prefix will expire after changing into historical versions for 60 days. + noncurrentVersionExpiration.setDays(60); + rule.setNoncurrentVersionExpiration(noncurrentVersionExpiration); + config.addRule(rule); + obsClient.setBucketLifecycle("examplebucket", config); + System.out.println("setBucketLifecycle successfully"); + } catch (ObsException e) { + System.out.println("setBucketLifecycle failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketLifecycle failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.
+This API returns the lifecycle rules of a bucket.
+obsClient.getBucketLifecycle(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters related to basic bucket information. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
rules + |
+List<Rule> + |
+Explanation: +List of lifecycle rules. For details, see Table 4. + |
+
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+No + |
+Explanation: +Lifecycle rule ID. +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
prefix + |
+String + |
+Yes + |
+Explanation: +Object name prefix. It identifies the objects the rule applies to. You can leave this parameter blank to apply the rule to all objects in the bucket. +Assume that you have the following objects: logs/day1, logs/day2, logs/day3, and ExampleObject.jpg. If you set prefix to ExampleObject.jpg, the rule applies to object ExampleObject.jpg only. If you set prefix to logs/, the rule applies to the three objects with name starting with logs/. If you leave prefix blank, the rule applies to all objects in the bucket. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
enabled + |
+boolean + |
+Yes + |
+Explanation: +Whether the rule is enabled. +Value range: +true: The rule is enabled. +false: The rule is disabled. +Default value: +None + |
+
expiration + |
++ | +No + |
+Explanation: +Expiration time of an object. For details, see Table 5. +Default value: +None + |
+
noncurrentVersionExpiration + |
++ | +No + |
+Explanation: +Expiration time of noncurrent object versions. For details, see Table 6. +Restrictions: +
Default value: +None + |
+
transitions + |
+List<Transition> + |
+No + |
+Explanation: +Policies for storage class transition, including transition time and the storage class after transition. For details, see Table 7. +Restrictions: +This parameter is only available for the current object version. +Default value: +None + |
+
noncurrentVersionTransitions + |
++ | +No + |
+Explanation: +Policies for storage class transition of noncurrent versions, including transition time and the storage class after transition. For details, see Table 9. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+Yes if date is absent during object storage class transition +Yes if date or expiredObjectDeleteMarker is absent during object deletion + |
+Explanation: +Number of days (since the last update was made to the object) after which the lifecycle rule takes effect (the object will be deleted). +Restrictions: +This parameter is only available for the current object version. +Value range: +A positive integer, in days. +Default value: +None + |
+
date + |
+Date + |
+Yes if days is absent during object storage class transition. +Yes if days or expiredObjectDeleteMarker is absent during object deletion + |
+Explanation: +The value must conform to the ISO8601 standards and indicate UTC 00:00. For example, 2018-01-01T00:00:00.000Z indicates only objects that were last modified before the specified time are transitioned to the specified storage class or deleted. +Default value: +None + |
+
expiredObjectDeleteMarker + |
+Boolean + |
+Yes if days or date is absent + |
+Explanation: +Whether to delete expired delete markers. The value can be true or false. If tags are configured in a lifecycle rule, this element cannot be configured. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+Yes + |
+Explanation: +Number of days an object is noncurrent before it expires. +Restrictions: +This parameter is only available for noncurrent object versions. +Value range: +A positive integer, in days. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+This parameter is mandatory if date is not configured. + |
+Explanation: +Number of days after its creation when the object is transitioned. +Restrictions: +This parameter is only available for the current object version. +Value range: +A positive integer, in days. +Default value: +None + |
+
date + |
+Date + |
+This parameter is mandatory if days is not configured. + |
+Explanation: +Date when the object will be transitioned. +Default value: +None + |
+
storageClass + |
++ | +Yes + |
+Explanation: +Storage class the object is transitioned to. +Restrictions: +Restrictions on storage class transitions:
+
Value range: +See Table 8. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
days + |
+Integer + |
+This parameter is mandatory if date is not configured. + |
+Explanation: +Number of days after its creation when the object is transitioned. +Restrictions: +This parameter is only available for noncurrent object versions. +Value range: +A positive integer, in days. +Default value: +None + |
+
storageClass + |
++ | +Yes + |
+Explanation: +Storage class the object is transitioned to. +Restrictions: +Restrictions on storage class transitions:
+
Value range: +See Table 8. +Default value: +None + |
+
This example returns the lifecycle configuration of bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.LifecycleConfiguration; +public class GetBucketLifecycle001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // View the lifecycle rules + LifecycleConfiguration config = obsClient.getBucketLifecycle("examplebucket"); + System.out.println("getBucketLifecycle successfully"); + for (LifecycleConfiguration.Rule rule : config.getRules()) { + System.out.println(rule.getId()); + System.out.println(rule.getPrefix()); + for (LifecycleConfiguration.Transition transition : rule.getTransitions()) { + System.out.println(transition.getDays()); + System.out.println(transition.getStorageClass()); + } + System.out.println(rule.getExpiration() != null ? rule.getExpiration().getDays() : ""); + for (LifecycleConfiguration.NoncurrentVersionTransition noncurrentVersionTransition : + rule.getNoncurrentVersionTransitions()) { + System.out.println(noncurrentVersionTransition.getDays()); + System.out.println(noncurrentVersionTransition.getStorageClass()); + } + System.out.println( + rule.getNoncurrentVersionExpiration() != null + ? rule.getNoncurrentVersionExpiration().getDays() + : ""); + } + } catch (ObsException e) { + System.out.println("getBucketLifecycle failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getBucketLifecycle failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.
+This API deletes the lifecycle configuration of a bucket.
+obsClient.deleteBucketLifecycle(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters related to basic bucket information. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes the lifecycle configurations of bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteBucketLifecycle001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete the lifecycle configurations. + obsClient.deleteBucketLifecycle("examplebucket"); + System.out.println("deleteBucketLifecycle successfully"); + } catch (ObsException e) { + System.out.println("deleteBucketLifecycle failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteBucketLifecycle failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Cross-origin access refers to access between different domains. Restricting cross-origin access is a browser policy for security purposes, that is, the same-origin policy.
+Due to this same-origin policy, JavaScript in origin A cannot operate objects in origin B or C.
+The same-origin policy requires the protocols, domain names (or IP addresses), and ports are all the same. If the protocols, domain names, and ports (if specified) of the two web pages are the same, the two web pages are in the same origin.
+Cross-origin resource sharing (CORS) allows web application programs in one origin to access resources in another.
+OBS supports CORS rules that allow the resources in OBS to be requested by other domains.
+ +For more information about the application scenarios of CORS, see:
+ +Cross-origin resource sharing (CORS) is a mechanism defined by the World Wide Web Consortium (W3C) that allows a web application program in one domain to access resources located in another one. For general web page requests, website scripts and contents in one domain cannot interact with those in another because of Same Origin Policies (SOPs). OBS supports CORS rules that allow the resources in OBS to be requested by other domains.
+You can call ObsClient.setBucketCors to set CORS rules for a bucket. The configured CORS rules follow the principle of new ones overwriting old ones.
+obsclient.setBucketCors(final SetBucketCorsRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Request parameters for setting a CORS rule. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
bucketCors + |
++ | +Yes + |
+Explanation: +List of CORS rules of a bucket. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
rules + |
+List<BucketCorsRule> + |
+Yes + |
+Explanation: +List of CORS rules of a bucket. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+No + |
+Explanation: +CORS rule ID. +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
allowedMethod + |
+List<String> + |
+Yes + |
+Explanation: +The allowed HTTP methods for a cross-origin request, indicating the operation types for buckets and objects. +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
allowedOrigin + |
+List<String> + |
+Yes + |
+Explanation: +The origin from which the requests can access the bucket. +Restrictions: +Domain name of the origin. Each origin can contain only one wildcard character (*), for example, https://*.vbs.example.com. +Default value: +None + |
+
allowedHeader + |
+List<String> + |
+No + |
+Explanation: +The allowed cross-origin request headers. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain only one wildcard character (*). Spaces, ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
maxAgeSeconds + |
+int + |
+No + |
+Explanation: +Duration your client can cache the response for a cross-origin request. +Restrictions: +Each bucket CORS rule can contain only one maxAgeSeconds. +Value range: +An integer greater than or equal to 0, in seconds. +Default value: +100 + |
+
exposeHeader + |
+List<String> + |
+No + |
+Explanation: +The CORS-allowed additional headers in the response. These headers provide additional information to clients. By default, your browser can only access headers Content-Length and Content-Type. If your browser needs to access other headers, add them to the list of the allowed additional headers. +Restrictions: +Spaces, wildcard characters (*), ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures CORS rules for bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketCors; +import com.obs.services.model.BucketCorsRule; +import com.obs.services.model.DeleteObjectsRequest; +import com.obs.services.model.DeleteObjectsResult; +import com.obs.services.model.KeyAndVersion; +import java.util.ArrayList; +import java.util.List; +public class SetBucketCors001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + //Configure CORS rules. + BucketCors cors = new BucketCors(); + List<BucketCorsRule> rules = new ArrayList<BucketCorsRule>(); + BucketCorsRule rule = new BucketCorsRule(); + ArrayList<String> allowedOrigin = new ArrayList<String>(); + // Specify the origin of the cross-origin request. + allowedOrigin.add( "http://www.a.com"); + allowedOrigin.add( "http://www.b.com"); + rule.setAllowedOrigin(allowedOrigin); + ArrayList<String> allowedMethod = new ArrayList<String>(); + // Specify the request method, which can be GET, PUT, DELETE, POST, or HEAD. + allowedMethod.add("GET"); + allowedMethod.add("HEAD"); + allowedMethod.add("PUT"); + rule.setAllowedMethod(allowedMethod); + ArrayList<String> allowedHeader = new ArrayList<String>(); + // Specify whether headers specified in Access-Control-Request-Headers in the OPTIONS request can be used. + allowedHeader.add("x-obs-header"); + rule.setAllowedHeader(allowedHeader); + ArrayList<String> exposeHeader = new ArrayList<String>(); + // Specify response headers that users can access using application programs. + exposeHeader.add("x-obs-expose-header"); + rule.setExposeHeader(exposeHeader); + // Specify the browser's cache time of the returned results of OPTIONS requests for specific resources, in seconds. + rule.setMaxAgeSecond(10); + rules.add(rule); + cors.setRules(rules); + obsClient.setBucketCors("examplebucket", cors); + System.out.println("setBucketCors successfully"); + } catch (ObsException e) { + System.out.println("setBucketCors failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketCors failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
CORS is a browser-standard mechanism defined by the W3C. It allows a web client in one origin to interact with resources in another. For general web page requests, website scripts and contents in one origin cannot interact with those in another due to SOPs. OBS supports CORS, allowing the resources in OBS to be requested across origins.
+This API returns the CORS configuration of a bucket.
+obsclient.getBucketCors(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for obtaining a CORS rule. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
rules + |
+List<BucketCorsRule> + |
+Yes + |
+Explanation: +List of CORS rules of a bucket. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+No + |
+Explanation: +CORS rule ID. +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
allowedMethod + |
+List<String> + |
+Yes + |
+Explanation: +The allowed HTTP methods for a cross-origin request, indicating the operation types for buckets and objects. +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
allowedOrigin + |
+List<String> + |
+Yes + |
+Explanation: +The origin from which the requests can access the bucket. +Restrictions: +Domain name of the origin. Each origin can contain only one wildcard character (*), for example, https://*.vbs.example.com. +Default value: +None + |
+
allowedHeader + |
+List<String> + |
+No + |
+Explanation: +The allowed cross-origin request headers. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain only one wildcard character (*). Spaces, ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
maxAgeSeconds + |
+int + |
+No + |
+Explanation: +Duration your client can cache the response for a cross-origin request. +Restrictions: +Each bucket CORS rule can contain only one maxAgeSeconds. +Value range: +An integer greater than or equal to 0, in seconds. +Default value: +100 + |
+
exposeHeader + |
+List<String> + |
+No + |
+Explanation: +The CORS-allowed additional headers in the response. These headers provide additional information to clients. By default, your browser can only access headers Content-Length and Content-Type. If your browser needs to access other headers, add them to the list of the allowed additional headers. +Restrictions: +Spaces, wildcard characters (*), ampersands (&), colons (:), and less-than signs (<) are not allowed. +Default value: +None + |
+
This example returns the CORS configuration of bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketCors; +import com.obs.services.model.BucketCorsRule; +public class GetBucketCors001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain the CORS rules. + BucketCors cors = obsClient.getBucketCors("examplebucket"); + for(BucketCorsRule rule : cors.getRules()){ + System.out.println("Id:" + rule.getId()); + System.out.println("MaxAgeSecond:" + rule.getMaxAgeSecond()); + System.out.println("AllowedHeader:" + rule.getAllowedHeader()); + System.out.println("AllowedOrigin:" + rule.getAllowedOrigin()); + System.out.println("AllowedMethod:" + rule.getAllowedMethod()); + System.out.println("ExposeHeader:" + rule.getExposeHeader()); + } + System.out.println("getBucketCors successfully"); + } catch (ObsException e) { + System.out.println("getBucketCors failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getBucketCors failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
CORS is a browser-standard mechanism defined by the W3C. It allows a web client in one origin to interact with resources in another. For general web page requests, website scripts and contents in one origin cannot interact with those in another due to SOPs. OBS supports CORS, allowing the resources in OBS to be requested across origins.
+This API deletes the CORS rules of a bucket.
+obsclient.deleteBucketCors(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for deleting a CORS rule. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes CORS rules of bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteBucketCors001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete CORS rules. + obsClient.deleteBucketCors("examplebucket"); + System.out.println("deleteBucketCors successfully"); + } catch (ObsException e) { + System.out.println("deleteBucketCors failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteBucketCors failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS allows you to configure access logging for buckets. After the configuration, access to buckets will be recorded in logs. These logs will be saved in specific buckets in OBS.
+You can enable OBS logging for bucket analysis or audit purposes. With access logs, a bucket owner can analyze the characteristics, types, or trends of requests sent to the bucket.
+With logging enabled, OBS automatically logs access requests for the bucket and writes the generated log files into a specified bucket.
+You need to specify a bucket for storing log files when enabling logging for a bucket. Log files can be stored in any bucket you own in the region where the logged bucket is, including the logged bucket itself.
+ +This API enables logging for a bucket (source) and configures another bucket (target) to store the log files. When a bucket is created, logging is not enabled by default. You can call this API to enable logging for the bucket. With logging enabled, a log message is generated for each operation on the bucket. Multiple log messages are packed into a file. The target bucket for storing log files must be specified when logging is enabled. It can be the bucket logging is enabled for, or any other bucket you have access to. If you specify another bucket for storing logs, the bucket must be in the same region as the logged bucket. You can also specify access permissions and name prefixes for log files.
+obsClient.setBucketLogging(final SetBucketLoggingRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for configuring logging for a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Name of the source bucket. +Restrictions: +
Default value: +None + |
+
loggingConfiguration + |
++ | +Yes + |
+Explanation: +Bucket logging configurations. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
agency + |
+String + |
+Yes if you configure bucket logging + |
+Explanation: +Name of the IAM agency created by the owner of the target bucket for OBS. +You can select an existing IAM agency or create one. +Restrictions: +By default, the IAM agency only requires the PutObject permission to upload logs to the target bucket. If default encryption is enabled for the target bucket, the agency also requires the KMS Administrator permission in the region where the target bucket is located. +Default value: +None + |
+
targetBucketName + |
+String + |
+No + |
+Explanation: +Name of the bucket for storing log files. +Restrictions: +
Default value: +None + |
+
logfilePrefix + |
+String + |
+No + |
+Explanation: +Name prefix for log files stored in the target bucket. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
targetGrantsList + |
+List<GrantAndPermission> + |
+No + |
+Explanation: +Permission information list of grantees, which defines grantees and their permissions for log files. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 5. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 8. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 6. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 7. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures logging for bucket examplebucket, with your agency as the agency, targetprefix as the prefix for generated log files, and targetbucketname as the bucket for storing log files.
+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 +49 +50 +51 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketLoggingConfiguration; +public class SetBucketLogging001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Enable bucket logging. + BucketLoggingConfiguration config = new BucketLoggingConfiguration(); + // Set an agency. You need to create one on IAM. + config.setAgency("your agency"); + config.setTargetBucketName("targetbucketname"); + config.setLogfilePrefix("targetprefix"); + obsClient.setBucketLogging("examplebucket", config); + System.out.println("setBucketLogging successfully"); + } catch (ObsException e) { + System.out.println("setBucketLogging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketLogging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example configures logging for bucket examplebucket, with your agency as the agency, targetprefix as the prefix for generated log files, and targetbucketname as the bucket for storing log files, and then grants all users the read permission for the logs.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketLoggingConfiguration; +import com.obs.services.model.GrantAndPermission; +import com.obs.services.model.GroupGrantee; +import com.obs.services.model.Permission; +public class SetBucketLogging002 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Configure access to logs. + String targetBucket = "targetbucketname"; + // Configure logging for the bucket. + BucketLoggingConfiguration config = new BucketLoggingConfiguration(); + // Set an agency. You need to create one on IAM. + config.setAgency("your agency"); + config.setTargetBucketName(targetBucket); + config.setLogfilePrefix("prefix"); + // Grant all users the READ permission for the logs. + GrantAndPermission grant1 = new GrantAndPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ); + config.setTargetGrants(new GrantAndPermission[]{grant1}); + obsClient.setBucketLogging("examplebucket", config); + System.out.println("setBucketLogging successfully"); + } catch (ObsException e) { + System.out.println("setBucketLogging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketLogging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example disables the logging for bucket examplebucket by clearing the logging configurations of the bucket using ObsClient.setBucketLogging.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketLoggingConfiguration; +public class SetBucketLogging003 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Leave the logging configurations in blank. + obsClient.setBucketLogging("examplebucket", new BucketLoggingConfiguration()); + System.out.println("setBucketLogging successfully"); + } catch (ObsException e) { + System.out.println("setBucketLogging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketLogging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This API returns the logging configuration of a bucket.
+obsClient.getBucketLogging(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for obtaining the logging configurations of a bucket. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
agency + |
+String + |
+Yes if you configure bucket logging + |
+Explanation: +Name of the IAM agency created by the owner of the target bucket for OBS. +You can select an existing IAM agency or create one. +Restrictions: +By default, the IAM agency only requires the PutObject permission to upload logs to the target bucket. If default encryption is enabled for the target bucket, the agency also requires the KMS Administrator permission in the region where the target bucket is located. +Default value: +None + |
+
targetBucketName + |
+String + |
+No + |
+Explanation: +Name of the bucket for storing log files. +Restrictions: +
Default value: +None + |
+
logfilePrefix + |
+String + |
+No + |
+Explanation: +Name prefix for log files stored in the target bucket. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
targetGrantsList + |
+List<GrantAndPermission> + |
+No + |
+Explanation: +Permission information list of grantees, which defines grantees and their permissions for log files. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 5. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 8. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 6. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 7. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
This example returns the logging configuration of bucket examplebucket.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketLoggingConfiguration; +public class GetBucketLogging001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // View the bucket logging configuration. + BucketLoggingConfiguration config = obsClient.getBucketLogging("examplebucket"); + System.out.println("TargetBucketName:" + config.getTargetBucketName()); + System.out.println("LogfilePrefix:" + config.getLogfilePrefix()); + System.out.println("getBucketLogging successfully"); + } catch (ObsException e) { + System.out.println("getBucketLogging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getBucketLogging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
To host your static website on OBS, you can upload static website files to your bucket as objects, configure the public read permission for the objects, and then configure static website hosting for your bucket.
+After this, when third-party users access your websites, they actually access the objects in your bucket in OBS.
+When using static website hosting, you can configure request redirection to redirect specific or all requests.
+For more information about the application scenarios of static website hosting, see:
+ +To host your static website on OBS, you can upload static website files to your bucket as objects, configure the public read permission for the objects, and then configure static website hosting for your bucket. After this, when third-party users access your website, they are accessing the objects in your bucket.
+obsClient.putObject(PutObjectRequest request)
+obsClient.setObjectAcl(SetObjectAclRequest acl)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for uploading an object. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
metadata + |
++ | +No + |
+Explanation: +Object metadata. For details, see Table 19. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +ACL that can be pre-defined when an object is created. Refer to Table 12 to choose the option you need. +Value range: +
Default value: +None + |
+
sseKmsHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 7. +Default value: +None + |
+
sseCHeader + |
++ | +No + |
+Explanation: +Server-side encryption header. For details, see Table 8. +Default value: +None + |
+
input + |
+java.io.InputStream + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Default value: +None + |
+
file + |
+java.io.File + |
+No + |
+Explanation: +File stream of the object to be uploaded. +Default value: +None + |
+
extensionPermissionMap + |
+Map<ExtensionObjectPermissionEnum, Set<String>> + |
+No + |
+Explanation: +A permission map for granting bucket ACL permissions to one or more accounts. ExtensionObjectPermissionEnum specifies the permissions to grant, and Set<String> describes the list of account IDs (indicated by domain_id) the granted permissions apply to. +Value range: +
Default value: +None + |
+
expires + |
+int + |
+No + |
+Explanation: +Expiration time of the object. The calculation starts from the time when the object was last modified. Once the object expires, it is automatically deleted. +Restrictions: +This parameter can be configured only during object upload and cannot be modified by calling a metadata API. +Value range: +An integer greater than 0, in days. +Default value: +None + |
+
progressListener + |
++ | +No + |
+Explanation: +Upload progress. For details, see Table 3. + |
+
encodeHeaders + |
+boolean + |
+No + |
+Explanation: +Whether to enable OBS to automatically encode request headers. +Value range: +true: Encoding with SDK is enabled. +false: Encoding with SDK is disabled. +Default value: +true + |
+
Method + |
+Return Value Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | +void + |
+Yes + |
+Explanation: +Used for obtaining the progress. For details, see Table 4. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
status + |
++ | +Yes + |
+Explanation: +Progress data. For details, see Table 5. +Default value: +None + |
+
Method + |
+Return Value Type + |
+Description + |
+
|---|---|---|
getAverageSpeed() + |
+double + |
+Average transmission rate. + |
+
getInstantaneousSpeed() + |
+double + |
+Instantaneous transmission rate. + |
+
getTransferPercentage() + |
+int + |
+Transmission progress, in percentage. + |
+
getNewlyTransferredBytes() + |
+long + |
+Number of the newly transmitted bytes. + |
+
getTransferredBytes() + |
+long + |
+Number of bytes that have been transmitted. + |
+
getTotalBytes() + |
+long + |
+Number of the bytes to be transmitted. + |
+
Constant + |
+Description + |
+
|---|---|
GRANT_READ + |
+Grants a specific tenant the permissions to read the object and object metadata. + |
+
GRANT_READ_ACP + |
+Grants a specific tenant the permissions to obtain the object ACL. + |
+
GRANT_WRITE_ACP + |
+Grants a specific tenant the permissions to write the object ACL. + |
+
GRANT_FULL_CONTROL + |
+Grants a specific tenant the permissions to read the content, metadata, and ACL of the object and write the object ACL. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
encryption + |
++ | +Yes + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Value range: +kms. For details, see Table 9. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only KMS is supported. +Value range: +See Table 10. +Default value: +None + |
+
kmsKeyId + |
+String + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
algorithm + |
++ | +Yes + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Value range: +AES256, indicating AES is used to encrypt the object in SSE-C. For details, see Table 11. +Default value: +None + |
+
sseAlgorithm + |
++ | +No + |
+Explanation: +Encryption algorithm. +Restrictions: +Only AES256 is supported. +Value range: +See Table 10. +Default value: +None + |
+
sseCKey + |
+byte[] + |
+Yes + |
+Explanation: +Key used for encrypting the object when SSE-C is used, in byte[] format. +Default value: +None + |
+
sseCKeyBase64 + |
+String + |
+No + |
+Explanation: +Base64-encoded key used for encrypting the object when SSE-C is used. +Default value: +None + |
+
Constant + |
+Default Value + |
+
|---|---|
KMS + |
+kms + |
+
AES256 + |
+AES256 + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Type + |
+
|---|---|---|---|
owner + |
++ | +No + |
+Explanation: +Bucket owner information. For details, see Table 13. + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
grants + |
+Set<GrantAndPermission> + |
+No + |
+Explanation: +Grantee information. For details, see Table 14. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
id + |
+String + |
+Yes + |
+Explanation: +Account (domain) ID of the bucket owner. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the owner. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantee + |
++ | +Yes + |
+Explanation: +Grantees (users or user groups). For details, see Table 16. + |
+
permission + |
++ | +Yes + |
+Explanation: +Permissions to grant. +Value range: +See Table 15. +Default value: +None + |
+
delivered + |
+boolean + |
+No + |
+Explanation: +Whether the bucket ACL is applied to all objects in the bucket. +Value range: +true: The bucket ACL is applied to all objects in the bucket. +false: The bucket ACL is not applied to any objects in the bucket. +Default value: +false + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
PERMISSION_READ + |
+READ + |
+Read permission. +A grantee with this permission for a bucket can obtain the list of objects, multipart uploads, bucket metadata, and object versions in the bucket. +A grantee with this permission for an object can obtain the object content and metadata. + |
+
PERMISSION_WRITE + |
+WRITE + |
+Write permission. +A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not available for objects. + |
+
PERMISSION_READ_ACP + |
+READ_ACP + |
+Permission to read an ACL. +A grantee with this permission can obtain the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. + |
+
PERMISSION_WRITE_ACP + |
+WRITE_ACP + |
+Permission to modify an ACL. +A grantee with this permission can update the ACL of a bucket or object. +A bucket or object owner has this permission for their bucket or object by default. +This permission allows the grantee to change the access control policies, meaning the grantee has full control over a bucket or object. + |
+
PERMISSION_FULL_CONTROL + |
+FULL_CONTROL + |
+Full control access, including read and write permissions for a bucket and its ACL, or for an object and its ACL. +A grantee with this permission for a bucket has READ, WRITE, READ_ACP, and WRITE_ACP permissions for the bucket. +A grantee with this permission for an object has READ, READ_ACP, and WRITE_ACP permissions for the object. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
| + | ++ | +Yes + |
+Explanation: +Grantee (user) information. For details, see Table 17. + |
+
| + | ++ | +Yes + |
+Explanation: +Grantee (user group) information. +Value range: +See Table 18. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
grantId + |
+String + |
+Yes if Type is set to GranteeUser + |
+Explanation: +Account (domain) ID of the grantee. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
displayName + |
+String + |
+No + |
+Explanation: +Account name of the grantee. +Value range: +To obtain the account name, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
ALL_USERS + |
+All users. + |
+
AUTHENTICATED_USERS + |
+Authorized users. This constant is deprecated. + |
+
LOG_DELIVERY + |
+Log delivery group. This constant is deprecated. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
contentLength + |
+Long + |
+No + |
+Explanation: +Object size. +Restrictions: +
Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
contentType + |
+String + |
+No + |
+Explanation: +MIME type of the object file. MIME type is a standard way of describing a data type and is used by the browser to decide how to display data. +Value range: +See What Is Content-Type (MIME)? +Default value: +If this parameter is not specified, the SDK determines the file type based on the suffix of the object name and assigns a value to the parameter. For example, if the suffix of the object name is .xml, the object is an application/xml file. If the suffix is .html, the object is a text/html file. + |
+
contentEncoding + |
+String + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies which encoding is applied to the object. +Default value: +None + |
+
contentDisposition + |
+String + |
+No + |
+Explanation: +Provides a default file name for the requested object. When the object with the default file name is being downloaded or accessed, the content is displayed as part of a web page in the browser or as an attachment in a download dialog box. +Default value: +None + |
+
cacheControl + |
+String + |
+No + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. +Default value: +None + |
+
contentLanguage + |
+String + |
+No + |
+Explanation: +Language or language combination for visitors to customize and use. For details, see the definition of ContentLanguage in the HTTP protocol. +Default value: +None + |
+
expires + |
+String + |
+No + |
+Explanation: +The time a cached web page object expires. +Restrictions: +The time must be in the GMT format. +Default value: +None + |
+
contentMd5 + |
+String + |
+No + |
+Explanation: +Base64-encoded MD5 value of the file data. It is provided for the OBS server to verify data integrity. The OBS server will compare this MD5 value with the MD5 value calculated based on the file data. If the two values are not the same, HTTP status code 400 is returned. +Restrictions: +
Value range: +Base64-encoded 128-bit MD5 value of the request body calculated according to RFC 1864. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
storageClass + |
++ | +No + |
+Explanation: +Storage class of an object that can be specified at object creation. If you do not specify this header, the object inherits the storage class of the bucket. +Value range: +See Table 20. +Default value: +None + |
+
webSiteRedirectLocation + |
+String + |
+No + |
+Explanation: +If the bucket is configured with website hosting, the request for obtaining the object can be redirected to another object in the bucket or an external URL. This parameter specifies the address the request for the object is redirected to. +The request is redirected to an object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL http://www.example.com/: +WebsiteRedirectLocation:http://www.example.com/ +Restrictions: +
Default value: +None + |
+
nextPosition + |
+long + |
+No + |
+Explanation: +Start position for the next append upload. +Value range: +0 to the object length, in bytes. +Default value: +None + |
+
appendable + |
+boolean + |
+No + |
+Explanation: +Whether the object is appendable. +Value range: +true: The object is appendable. +false: The object is not appendable. +Default value: +None + |
+
userMetadata + |
+Map<String, Object> + |
+No + |
+Explanation: +User-defined metadata of the object. To define it, you can add a header starting with x-obs-meta- in the request. In Map, the String key indicates the name of the user-defined metadata that starts with x-obs-meta-, and the Object value indicates the value of the user-defined metadata. To obtain the user-defined metadata of an object, use ObsClient.getObjectMetadata. For details, see Obtaining Object Metadata. +Restrictions: +
Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
STANDARD + |
+STANDARD + |
+Standard storage class + |
+
WARM + |
+WARM + |
+Warm storage class. + |
+
COLD + |
+COLD + |
+Cold storage class. + |
+
Constant + |
+Description + |
+
|---|---|
AccessControlList.REST_CANNED_PRIVATE + |
+Private read/write. +A bucket or object can only be accessed by its owner. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ + |
+Public read. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, bucket metadata, and object versions in the bucket. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE + |
+Public read/write. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart uploads, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, anyone can read the content and metadata of the object. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_DELIVERED + |
+Public read on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, and bucket metadata, and can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_PUBLIC_READ_WRITE_DELIVERED + |
+Public read/write on a bucket as well as objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, and bucket metadata, and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of the objects in the bucket. +This permission cannot be granted on objects. + |
+
AccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL + |
+If this permission is granted on an object, only the bucket and object owners have the full control over the object. +By default, if you upload an object to a bucket owned by another user, the bucket owner does not have the permissions on your object. After you grant this permission to the bucket owner, the bucket owner can have full control over your object. +For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets bucket-owner-full-control for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for setting an object ACL. For details, see Table 23. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
objectKey + |
+String + |
+Yes + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
versionId + |
+String + |
+No + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
acl + |
++ | +No + |
+Explanation: +An ACL specified for the object. You can use either a pre-defined or a user-defined ACL. +Value range: +
Default value: +AccessControlList.REST_CANNED_PRIVATE + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +Response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
storageClass + |
++ | +Explanation: +Object storage class. If the storage class is Standard, leave this parameter blank. +Value range: +See Table 20. +Default value: +None + |
+
versionId + |
+String + |
+Explanation: +Object version ID. If versioning is enabled for the bucket, the object version number will be returned. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
etag + |
+String + |
+Explanation: +ETag of an object, which is a Base64-encoded 128-bit MD5 digest. ETag is the unique identifier of the object content. It can be used to determine whether the object content is changed. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, the object content is changed. The ETag reflects changes only to the contents of the object, not its metadata. An object created by an upload or copy operation has a unique ETag. +Restrictions: +If an object is encrypted using server-side encryption, the ETag is not the MD5 value of the object. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
objectKey + |
+String + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path that does not contain the bucket name. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
bucketName + |
+String + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures static website hosting for bucket examplebucket by specifying the MIME type and setting the object ACL to public read.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.AccessControlList; +import com.obs.services.model.ObjectMetadata; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Sample code is as follows: + // Upload an object and set the MIME type for the object. + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("test.html"); + request.setFile(new File("localfile.html")); + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setContentType("text/html"); + request.setMetadata(metadata); + obsClient.putObject(request); + // Set the object ACL to public read. + obsClient.setObjectAcl("examplebucket", "test.html", AccessControlList.REST_CANNED_PUBLIC_READ); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
In this code example, you can use https://bucketname.your-endpoint/test.html to access the hosted file in the browser.
+You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using the bucket's website endpoint to end users. Typical use cases include:
+This API configures static website hosting for a bucket.
+obsClient.setBucketWebsite(final SetBucketWebsiteRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for configuring website hosting. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value must contain 3 to 63 characters. + |
+
websiteConfig + |
++ | +Yes + |
+Explanation: +Static website hosting configurations. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
suffix + |
+String + |
+No + |
+Explanation: +Suffix that is appended to the request for a directory. For example, if the suffix is index.html and you request samplebucket/images/, the returned data will be for the object named images/index.html in the bucket samplebucket. +Restrictions: +
Value range: +This parameter can neither be left blank nor contain slashes (/). +Default value: +None + |
+
key + |
+String + |
+No + |
+Explanation: +Object name to use when a 4XX error occurs. This parameter specifies the web page to display when an error occurs. +Restrictions: +
Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
routeRules + |
+List<RouteRule> + |
+No + |
+Explanation: +List of routing rules. For details, see Table 6. +Restrictions: +
Default value: +None + |
+
redirectAllRequestsTo + |
++ | +No + |
+Explanation: +Redirection rules for all requests. For details, see Table 4. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
hostName + |
+String + |
+Yes + |
+Explanation: +Host name used for redirection, for example, www.example.com. +Restrictions: +The host name must comply with the host name rules. +Default value: +None + |
+
protocol + |
++ | +No + |
+Explanation: +Protocol used for redirection. +Value range: +See Table 5. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
HTTP + |
+http + |
+HTTP protocol used for redirection. + |
+
HTTPS + |
+https + |
+HTTPS protocol used for redirection. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
condition + |
++ | +No + |
+Explanation: +Conditions of a redirection rule. For details, see Table 7. + |
+
redirect + |
++ | +Yes + |
+Explanation: +Details about the redirection. For details, see Table 8. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
keyPrefixEquals + |
+String + |
+No + |
+Explanation: +Object name prefix for the redirection to take effect. If the name prefix of the requested object is the same as the value specified for this parameter, the redirection rule takes effect. +For example, to redirect the requests for the object ExamplePage.html, set keyPrefixEquals to ExamplePage.html. +Restrictions: +This parameter cannot be used together with httpErrorCodeReturnedEquals. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
httpErrorCodeReturnedEquals + |
+String + |
+No + |
+Explanation: +HTTP error code for the redirection to take effect. If there is an error, and the error code returned is the same as the value specified for this parameter, the redirection rule takes effect. +For example, if you want to redirect requests to NotFound.html when HTTP error code 404 is returned, set httpErrorCodeReturnedEquals to 404 in RouteRuleCondition, and set replaceKeyWith to NotFound.html in Redirect. +Restrictions: +This parameter cannot be used together with keyPrefixEquals. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Protocol + |
++ | +No + |
+Explanation: +Protocol used for redirection. +Value range: +See Table 5. +Default value: +None + |
+
hostName + |
+String + |
+No + |
+Explanation: +Host name used for redirection. +Default value: +None + |
+
replaceKeyPrefixWith + |
+String + |
+No + |
+Explanation: +Object name prefix used in the redirection request. +Restrictions: +This parameter cannot be used together with replaceKeyWith. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
replaceKeyWith + |
+String + |
+No + |
+Explanation: +Object name used in the redirection request. +Restrictions: +This parameter cannot be used together with replaceKeyPrefixWith. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
httpRedirectCode + |
+String + |
+No + |
+Explanation: +HTTP status code in the response to the redirect request. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures the default homepage and error pages for bucket examplebucket.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.WebsiteConfiguration; +public class SetBucketWebsite001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Sample code is as follows: + WebsiteConfiguration config = new WebsiteConfiguration(); + // Configure the default homepage. + config.setSuffix("index.html"); + // Configure the error pages. + config.setKey("error.html"); + obsClient.setBucketWebsite("examplebucket", config); + System.out.println("setBucketWebsite successfully"); + } catch (ObsException e) { + System.out.println("setBucketWebsite failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketWebsite failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example configures a redirection rule for bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ProtocolEnum; +import com.obs.services.model.Redirect; +import com.obs.services.model.RouteRule; +import com.obs.services.model.RouteRuleCondition; +import com.obs.services.model.WebsiteConfiguration; +public class SetBucketWebsite002 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Sample code is as follows: + WebsiteConfiguration config = new WebsiteConfiguration(); + // Configure the default homepage. + config.setSuffix("index.html"); + // Configure the error pages. + config.setKey("error.html"); + RouteRule rule = new RouteRule(); + Redirect r = new Redirect(); + r.setHostName("www.example.com"); + r.setHttpRedirectCode("305"); + r.setRedirectProtocol(ProtocolEnum.HTTP); + r.setReplaceKeyPrefixWith("replacekeyprefix"); + rule.setRedirect(r); + RouteRuleCondition condition = new RouteRuleCondition(); + condition.setHttpErrorCodeReturnedEquals("404"); + condition.setKeyPrefixEquals("keyprefix"); + rule.setCondition(condition); + config.getRouteRules().add(rule); + obsClient.setBucketWebsite("examplebucket", config); + System.out.println("setBucketWebsite successfully"); + } catch (ObsException e) { + System.out.println("setBucketWebsite failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketWebsite failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example configures redirection of all requests for bucket examplebucket.
+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 +49 +50 +51 +52 +53 +54 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ProtocolEnum; +import com.obs.services.model.RedirectAllRequest; +import com.obs.services.model.WebsiteConfiguration; +public class SetBucketWebsite003 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Sample code is as follows: + WebsiteConfiguration config = new WebsiteConfiguration(); + RedirectAllRequest redirectAll = new RedirectAllRequest(); + redirectAll.setHostName("www.example.com"); + redirectAll.setRedirectProtocol(ProtocolEnum.HTTP); + config.setRedirectAllRequestsTo(redirectAll); + obsClient.setBucketWebsite("examplebucket", config); + System.out.println("setBucketWebsite successfully"); + } catch (ObsException e) { + System.out.println("setBucketWebsite failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketWebsite failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using the bucket's website endpoint to end users. Typical use cases include:
+This API returns the static website hosting configurations of the bucket.
+obsClient.getBucketWebsite(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters related to basic bucket information. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
suffix + |
+String + |
+No + |
+Explanation: +Suffix that is appended to the request for a directory. For example, if the suffix is index.html and you request samplebucket/images/, the returned data will be for the object named images/index.html in the bucket samplebucket. +Value range: +This parameter can neither be left blank nor contain slashes (/). +Default value: +None + |
+
key + |
+String + |
+No + |
+Explanation: +Object name to use when a 4XX error occurs. This parameter specifies the web page to display when an error occurs. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
redirectAllRequestsTo + |
++ | +No + |
+Explanation: +Redirection rules for all requests. For details, see Table 4. + |
+
routeRules + |
+List<RouteRule> + |
+No + |
+Explanation: +List of routing rules. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
hostName + |
+String + |
+Yes + |
+Explanation: +Host name used for redirection, for example, www.example.com. +Restrictions: +The host name must comply with the host name rules. +Default value: +None + |
+
protocol + |
++ | +No + |
+Explanation: +Protocol used for redirection. +Value range: +See Table 5. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
HTTP + |
+http + |
+HTTP protocol used for redirection. + |
+
HTTPS + |
+https + |
+HTTPS protocol used for redirection. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
condition + |
++ | +No + |
+Explanation: +Conditions of a redirection rule. For details, see Table 7. + |
+
redirect + |
++ | +Yes + |
+Explanation: +Details about the redirection. For details, see Table 8. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
keyPrefixEquals + |
+String + |
+No + |
+Explanation: +Object name prefix for the redirection to take effect. If the name prefix of the requested object is the same as the value specified for this parameter, the redirection rule takes effect. +For example, to redirect the requests for the object ExamplePage.html, set keyPrefixEquals to ExamplePage.html. +Restrictions: +This parameter cannot be used together with httpErrorCodeReturnedEquals. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
httpErrorCodeReturnedEquals + |
+String + |
+No + |
+Explanation: +HTTP error code for the redirection to take effect. If there is an error, and the error code returned is the same as the value specified for this parameter, the redirection rule takes effect. +For example, if you want to redirect requests to NotFound.html when HTTP error code 404 is returned, set httpErrorCodeReturnedEquals to 404 in RouteRuleCondition, and set replaceKeyWith to NotFound.html in Redirect. +Restrictions: +This parameter cannot be used together with keyPrefixEquals. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Protocol + |
++ | +No + |
+Explanation: +Protocol used for redirection. +Value range: +See Table 5. +Default value: +None + |
+
hostName + |
+String + |
+No + |
+Explanation: +Host name used for redirection. +Default value: +None + |
+
replaceKeyPrefixWith + |
+String + |
+No + |
+Explanation: +Object name prefix used in the redirection request. +Restrictions: +This parameter cannot be used together with replaceKeyWith. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
replaceKeyWith + |
+String + |
+No + |
+Explanation: +Object name used in the redirection request. +Restrictions: +This parameter cannot be used together with replaceKeyPrefixWith. +Value range: +The value must contain 1 to 1,024 characters. +Default value: +None + |
+
httpRedirectCode + |
+String + |
+No + |
+Explanation: +HTTP status code in the response to the redirect request. +Default value: +None + |
+
This example returns the website configuration of bucket examplebucket using obsClient.getBucketWebsite.
+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 +49 +50 +51 +52 +53 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.RouteRule; +import com.obs.services.model.WebsiteConfiguration; +public class GetBucketWebsite001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // View the website configuration of the bucket. + WebsiteConfiguration config = obsClient.getBucketWebsite("examplebucket"); + System.out.println("Key:" + config.getKey()); + System.out.println("Suffix:" + config.getSuffix()); + for(RouteRule rule : config.getRouteRules()){ + System.out.println("rule:" +rule); + } + System.out.println("getBucketWebsite successfully"); + } catch (ObsException e) { + System.out.println("getBucketWebsite failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getBucketWebsite failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
You can host static website resources such as HTML web pages, flash files, or audio and video files in an OBS bucket, so that you can provide these hosted resources using the bucket's website endpoint to end users. Typical use cases include:
+This API deletes the static website hosting configurations of a bucket.
+obsClient.deleteBucketWebsite(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters related to basic bucket information. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes the website configuration of bucket examplebucket using obsClient.deleteBucketWebsite.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteBucketWebsite001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete the website configuration of the bucket. + obsClient.deleteBucketWebsite("examplebucket"); + System.out.println("deleteBucketWebsite successfully"); + } catch (ObsException e) { + System.out.println("deleteBucketWebsite failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteBucketWebsite failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
Tags are used to identify and classify OBS buckets.
+If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analysis.
+For example, if you have an application that uploads its running data to a bucket, you can tag the bucket with the application name.
+In this manner, the costs of the application can be analyzed using tags in SDRs.
+For details about the application scenarios of bucket tags, see:
+ + +If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analysis. For example, if you have an application that uploads its running data to a bucket, you can tag the bucket with the application name. In this manner, the costs of the application can be analyzed using tags in SDRs.
+This API adds tags to a bucket.
+obsClient.setBucketTagging(final SetBucketTaggingRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters for setting bucket tags. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
bucketTagInfo + |
++ | +Yes + |
+Explanation: +Bucket tag information. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
tagSet + |
++ | +Yes + |
+Explanation: +Tag set. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
tags + |
+List<Tag> + |
+Yes + |
+Explanation: +Tag list. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
key + |
+String + |
+Yes + |
+Explanation: +Tag key. +Restrictions: +
Default value: +None + |
+
value + |
+String + |
+Yes + |
+Explanation: +Tag value. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example configures tags for bucket examplebucket using ObsClient.setBucketTagging.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketTagInfo; +public class SetBucketTagging001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Configure tags for the bucket. + BucketTagInfo bucketTagInfo = new BucketTagInfo(); + BucketTagInfo.TagSet tagSet = new BucketTagInfo.TagSet(); + tagSet.addTag("tag1", "value1"); + tagSet.addTag("tag2", "value2"); + bucketTagInfo.setTagSet(tagSet); + obsClient.setBucketTagging("examplebucket", bucketTagInfo); + System.out.println("setBucketTagging successfully"); + } catch (ObsException e) { + System.out.println("setBucketTagging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("setBucketTagging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analysis. For example, if you have an application that uploads its running data to a bucket, you can tag the bucket with the application name. In this manner, the costs of the application can be analyzed using tags in SDRs.
+This API returns the tags of a bucket.
+obsClient.getBucketTagging(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters related to basic bucket information. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
tagSet + |
++ | +Explanation: +Tag set. For details, see Table 4. + |
+
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
tags + |
+List<Tag> + |
+Explanation: +Tag list. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
key + |
+String + |
+Yes + |
+Explanation: +Tag key. +Restrictions: +
Default value: +None + |
+
value + |
+String + |
+Yes + |
+Explanation: +Tag value. +Restrictions: +
Default value: +None + |
+
This example returns tags of bucket examplebucket using obsClient.getBucketTagging.
+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 +49 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.BucketTagInfo; +public class GetBucketTagging001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Obtain bucket tags. + BucketTagInfo bucketTagInfo = obsClient.getBucketTagging("examplebucket"); + for(BucketTagInfo.TagSet.Tag tag : bucketTagInfo.getTagSet().getTags()){ + System.out.println("\t" + tag.getKey() + ":" + tag.getValue());} + System.out.println("getBucketTagging successfully"); + } catch (ObsException e) { + System.out.println("getBucketTagging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getBucketTagging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
If you add tags to a bucket, SDRs generated for the requests sent to this bucket will include these tags, so you can use the tags to classify SDRs for detailed cost analysis. For example, if you have an application that uploads its running data to a bucket, you can tag the bucket with the application name. In this manner, the costs of the application can be analyzed using tags in SDRs.
+This API deletes the tags of a bucket.
+obsClient.deleteBucketTagging(final BaseBucketRequest request)
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
request + |
++ | +Yes + |
+Explanation: +Request parameters related to basic bucket information. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
bucketName + |
+String + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
statusCode + |
+int + |
+Explanation: +HTTP status code. +Value range: +A status code is a group of digits that can be 2xx (indicating successes) or 4xx or 5xx (indicating errors). It indicates the status of a response. +Default value: +None + |
+
responseHeaders + |
+Map<String, Object> + |
+Explanation: +HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. +Default value: +None + |
+
This example deletes tags of bucket examplebucket using ObsClient.deleteBucketTagging.
+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 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +public class DeleteBucketTagging001 +{ + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is to be created. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Delete bucket tags. + obsClient.deleteBucketTagging("examplebucket"); + System.out.println("deleteBucketTagging successfully"); + } catch (ObsException e) { + System.out.println("deleteBucketTagging failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("deleteBucketTagging failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
OBS provides server-side encryption for objects, so that they will be encrypted or decrypted when you upload them to or download them from a bucket.
+The encryption and decryption happen on the server side.
+There are different encryption methods for you to choose from.
+With SSE-KMS, OBS uses the keys provided by Key Management Service (KMS) for server-side encryption. You can create custom keys for SSE-KMS encryption.
+With SSE-C, OBS uses the keys and MD5 values of the keys provided by customers for server-side encryption.
+When server-side encryption is used, the returned ETag value is not the object's MD5 value. OBS will verify the object's MD5 value as long as the upload request includes the Content-MD5 header, no matter whether server-side encryption is used or not.
+When server-side encryption is used, you are advised to use HTTPS to transmit and receive data.
+ +The following table lists APIs related to server-side encryption:
+ +Method in OBS Java SDK + |
+Description + |
+Supported Encryption Type + |
+
|---|---|---|
ObsClient.putObject + |
+Sets the encryption algorithm and key during object upload to enable server-side encryption. + |
+SSE-KMS +SSE-C + |
+
ObsClient.getObject + |
+Users with the KMS Administrator permission can directly download objects encrypted using KMS. During a download, the backend decrypts KMS-encrypted objects before returning them. (SSE-KMS) +Sets the decryption algorithm and key during object download to decrypt the object. (SSE-C) + |
+SSE-KMS +SSE-C + |
+
ObsClient.copyObject + |
+
|
+SSE-KMS +SSE-C + |
+
ObsClient.getObjectMetadata + |
+Sets the decryption algorithm and key when obtaining the object metadata to decrypt the object. + |
+SSE-C + |
+
ObsClient.initiateMultipartUpload + |
+Sets the encryption algorithm and key when initializing a multipart upload to enable server-side encryption for the final object generated. + |
+SSE-KMS +SSE-C + |
+
ObsClient.uploadPart + |
+Sets the encryption algorithm and key during multipart upload to enable server-side encryption for parts. + |
+SSE-C + |
+
ObsClient.copyPart + |
+
|
+SSE-C + |
+
The following code shows an example of encrypting an object with SSE-C before uploading it:
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 | // Hard-coded or plaintext access keys (AK/SK) are risky. For security purposes, encrypt your access keys and store them in the configuration file or environment variables. In this example, access keys are stored in the environment variables for identity authentication. Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(ak, sk, endPoint); + +PutObjectRequest request = new PutObjectRequest(); +request.setBucketName("bucketname"); +request.setObjectKey("objectname"); +request.setFile(new File("localfile")); + +HashMap<String, String> userHeaders = new HashMap<>(); +userHeaders.put("x-obs-server-side-encryption-customer-algorithm","AES256"); +//The key for encrypting objects when SSE-C is used. Its value is a Base64-encoded 256-bit key. +userHeaders.put("x-obs-server-side-encryption-customer-key","your-encryption-customer-key"); +userHeaders.put("x-obs-server-side-encryption-customer-key-MD5", + ServiceUtils.toBase64(ServiceUtils.computeMD5Hash(ServiceUtils.fromBase64("your-encryption-customer-key")))); request.setUserHeaders(userHeaders); +HeaderResponse response = obsClient.putObject(request); +System.out.println("response:"+response.getRequestId()); + |
The following code shows an example of downloading an object encrypted with SSE-C:
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.internal.utils.ServiceUtils; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObsObject; +import java.util.HashMap; +import java.util.Map; + +public class SseCGetObject{ + public static void main(String[] args) { + // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables for identity authentication. + //Before running the code in this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Create an ObsClient instance and use the permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use the temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Call APIs to perform operations, for example, downloading an encrypted object. + GetObjectRequest request=new GetObjectRequest("bucketname","objectname"); + // Set the SSE-C decryption algorithm. + HashMap<String, String> userHeaders=new HashMap<>(); + userHeaders.put("x-obs-server-side-encryption-customer-algorithm","AES256"); + The header indicates the key used to encrypt objects in SSE-C mode. The header value is a Base64-encoded 256-bit key. + userHeaders.put("x-obs-server-side-encryption-customer-key","your-encryption-customer-key"); + userHeaders.put("x-obs-server-side-encryption-customer-key-MD5", + ServiceUtils.toBase64(ServiceUtils.computeMD5Hash(ServiceUtils.fromBase64("your-encryption-customer-key")))); + request.setUserHeaders(userHeaders); + ObsObject obsObject=obsClient.getObject(request); + // You can use other methods to read streams. + System.out.println(obsObject.getObjectContent()); + } + catch(ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + Map<String, String> headers=e.getResponseHeaders(); + if(headers!=null){ + Check all map entries and print all headers with errors reported. + for(Map.Entry<String, String> header:headers.entrySet()){ + if(header.getKey().contains("error")){ + System.out.println(header.getKey()+":"+header.getValue()); + } + } + } + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
The OBS server complies with the HTTP standard. After an API is called, the OBS server returns a standard HTTP status code. The following tables list the categories of HTTP status codes and the common HTTP status codes in OBS.
+Category + |
+Description + |
+
|---|---|
1XX + |
+Informational response. A request is received by the server and the server requires the requester to continue the operation. This category is usually invisible to the client. + |
+
2XX + |
+Success. The operation is received and processed successfully. + |
+
3XX + |
+Redirection. Further operations to complete the request are required. This category is usually invisible to the client. + |
+
4XX + |
+Client errors. The request contains a syntax error, or the request cannot be implemented. + |
+
5XX + |
+Server errors. There is an error when the server is processing a request. + |
+
HTTP Status Code + |
+Description + |
+Possible Cause + |
+
|---|---|---|
400 Bad Request + |
+The request parameter is incorrect. + |
+
|
+
403 Forbidden + |
+The access is denied. + |
+
|
+
404 Not Found + |
+The requested resource does not exist. + |
+
|
+
405 Method Not Allowed + |
+The request method is not supported. + |
+The request method or feature is not supported in the region where the bucket is located. + |
+
408 Request Timeout + |
+Request timed out. + |
+The Socket connection between the server and client times out. + |
+
409 Conflict + |
+Request conflicts occur. + |
+
|
+
500 Internal Server Error + |
+An internal error occurs on the server side. + |
+An internal error occurs on the server side. + |
+
503 Service Unavailable + |
+The service is unavailable. + |
+The server is inaccessible temporarily. + |
+
If the OBS server encounters an error when processing a request, a response containing the error code and error description is returned. The following table lists details about each error code and HTTP status code.
+ +HTTP Status Code + |
+Error Code + |
+Error Message + |
+Solution + |
+
|---|---|---|---|
301 Moved Permanently + |
+PermanentRedirect + |
+The requested bucket can be accessed only through the specified address. Send subsequent requests to the address. + |
+Send the request to the returned redirection address. + |
+
301 Moved Permanently + |
+WebsiteRedirect + |
+The website request lacks bucketName. + |
+Put the bucket name in the request and try again. + |
+
307 Moved Temporarily + |
+TemporaryRedirect + |
+Temporary redirection. If the DNS is updated, the request is redirected to the bucket. + |
+The system automatically redirects the request or sends the request to the redirection address. + |
+
400 Bad Request + |
+BadDigest + |
+The specified value of Content-MD5 does not match the value received by OBS. + |
+Check whether the MD5 value carried in the header is the same as that calculated by the message body. + |
+
400 Bad Request + |
+BadDomainName + |
+Invalid domain name. + |
+Use a valid domain name. + |
+
400 Bad Request + |
+BadRequest + |
+Invalid request parameter. + |
+Modify the parameter according to the error details returned in the message body. + |
+
400 Bad Request + |
+CustomDomainAreadyExist + |
+The configured domain already exists. + |
+It has been configured and does not need to be configured again. + |
+
400 Bad Request + |
+CustomDomainNotExist + |
+The domain to be deleted does not exist. + |
+The domain is not configured or has been deleted. You do not need to delete it. + |
+
400 Bad Request + |
+EntityTooLarge + |
+The size of the object uploaded using the POST method exceeds the upper limit. + |
+Modify the conditions specified in the policy when posting the object or reduce the object size. + |
+
400 Bad Request + |
+EntityTooSmall + |
+The size of the object uploaded using the POST method does not reach the lower limit. + |
+Modify the conditions specified in the policy when posting the object or increase the object size. + |
+
400 Bad Request + |
+IllegalLocationConstraintException + |
+A request without Location is sent for creating a bucket in a non-default region. + |
+Send the bucket creation request to the default region, or send the request with the Location of the non-default region. + |
+
400 Bad Request + |
+IncompleteBody + |
+No complete request body is received due to network or other problems. + |
+Upload the object again. + |
+
400 Bad Request + |
+IncorrectNumberOfFilesInPost Request + |
+Each POST request must contain one file to be uploaded. + |
+Carry a file to be uploaded. + |
+
400 Bad Request + |
+InvalidArgument + |
+Invalid parameter. + |
+Modify the parameter according to the error details in the message body. + |
+
400 Bad Request + |
+InvalidBucket + |
+The bucket to be accessed does not exist. + |
+Try another bucket name. + |
+
400 Bad Request + |
+InvalidBucketName + |
+The bucket name specified in the request is invalid, which may have exceeded the maximum length, or contain special characters that are not allowed. + |
+Try another bucket name. + |
+
400 Bad Request + |
+InvalidEncryptionAlgorithmError + |
+Incorrect encryption algorithm. The object cannot be decrypted due to incorrect encryption header carried when downloading the SSE-C encrypted object. + |
+Carry the correct encryption header when downloading the object. + |
+
400 Bad Request + |
+InvalidLocationConstraint + |
+The specified Location in the bucket creation request is invalid or does not exist. + |
+Correct the Location in the bucket creation request. + |
+
400 Bad Request + |
+InvalidPart + |
+One or more specified parts are not found. The parts may not be uploaded or the specified entity tags (ETags) do not match the parts' ETags. + |
+Specify the correct parts and entity tags. + |
+
400 Bad Request + |
+InvalidPartOrder + |
+Parts are not listed in ascending order by part number. + |
+Sort the parts in ascending order and assemble them again. + |
+
400 Bad Request + |
+InvalidPolicyDocument + |
+The content of the form does not meet the conditions specified in the policy document. + |
+Modify the policy in the constructed form according to the error details in the message body and try again. + |
+
400 Bad Request + |
+InvalidRedirectLocation + |
+Invalid redirect location. + |
+Specify the correct IP address. + |
+
400 Bad Request + |
+InvalidRequest + |
+Invalid request. + |
+Modify the parameter according to the error details returned in the message body. + |
+
400 Bad Request + |
+InvalidRequestBody + |
+The request body is invalid. The request requires a message body but no message body is uploaded. + |
+Upload the message body in the correct format. + |
+
400 Bad Request + |
+InvalidTargetBucketForLogging + |
+The delivery group has no ACL permission for the target bucket. + |
+Configure the target bucket ACL and try again. + |
+
400 Bad Request + |
+KeyTooLongError + |
+The provided key is too long. + |
+Use a shorter key. + |
+
400 Bad Request + |
+KMS.DisabledException + |
+The master key is disabled in server-side encryption with KMS-managed keys (SSE-KMS) mode. + |
+Replace the key and try again, or contact with the technical support. + |
+
400 Bad Request + |
+KMS.NotFoundException + |
+The master key does not exist in SSE-KMS mode. + |
+Retry with the correct master key. + |
+
400 Bad Request + |
+MalformedACLError + |
+The XML file you provided was not well-formed or did not validate against our format requirements. + |
+Use the correct XML format to retry. + |
+
400 Bad Request + |
+MalformedError + |
+The XML format in the request is incorrect. + |
+Use the correct XML format to retry. + |
+
400 Bad Request + |
+MalformedLoggingStatus + |
+The XML format of Logging is incorrect. + |
+Use the correct XML format to retry. + |
+
400 Bad Request + |
+MalformedPolicy + |
+The bucket policy failed the check. + |
+Modify the bucket policy according to the error details returned in the message body. + |
+
400 Bad Request + |
+MalformedQuotaError + |
+The Quota XML format is incorrect. + |
+Use the correct XML format to retry. + |
+
400 Bad Request + |
+MalformedXML + |
+An XML file of a configuration item is in incorrect format. + |
+Use the correct XML format to retry. + |
+
400 Bad Request + |
+MaxMessageLengthExceeded + |
+Copying an object does not require a message body in the request. + |
+Remove the message body and retry. + |
+
400 Bad Request + |
+MetadataTooLarge + |
+The size of the metadata header has exceeded the upper limit. + |
+Reduce the size of the metadata header. + |
+
400 Bad Request + |
+MissingRegion + |
+No region contained in the request and no default region defined in the system. + |
+Carry the region information in the request. + |
+
400 Bad Request + |
+MissingRequestBodyError + |
+An empty XML file is sent as a request. + |
+Provide the correct XML file. + |
+
400 Bad Request + |
+MissingRequiredHeader + |
+A required header is missing in the request. + |
+Provide the required header. + |
+
400 Bad Request + |
+MissingSecurityHeader + |
+A required header is missing in the request. + |
+Provide the required header. + |
+
400 Bad Request + |
+TooManyBuckets + |
+You have attempted to create more buckets than allowed. + |
+Delete some buckets and try again. + |
+
400 Bad Request + |
+TooManyCustomDomains + |
+Too many user accounts are configured. + |
+Delete some user accounts and try again. + |
+
400 Bad Request + |
+TooManyWrongSignature + |
+The request is rejected due to high-frequency errors. + |
+Replace AK and try again. + |
+
400 Bad Request + |
+UnexpectedContent + |
+The request requires a message body which is not carried by the client, or the request does not require a message body but the client carries the message body. + |
+Try again according to the instruction. + |
+
400 Bad Request + |
+AZRedundancyTypeNotSupported + |
+The current region does not support buckets with this AZ redundancy. + |
+Choose a type of AZ redundancy supported in the region. + |
+
400 Bad Request + |
+UserKeyMustBeSpecified + |
+This operation is only available to special users. + |
+Contact the technical support. + |
+
403 Forbidden + |
+AccessDenied + |
+Access denied, because the request does not carry a date header or the header format is incorrect. + |
+Provide a correct date header in the request. + |
+
403 Forbidden + |
+AccessForbidden + |
+Insufficient permission. No CORS rule is configured for the bucket or the CORS rule does not match. + |
+Modify the CORS configuration of the bucket or send the matched OPTIONS request based on the CORS configuration of the bucket. + |
+
403 Forbidden + |
+AllAccessDisabled + |
+You have no permission to perform the operation. The bucket name is forbidden. + |
+Change the bucket name. + |
+
403 Forbidden + |
+DeregisterUserId + |
+The user has been deregistered. + |
+Top up or re-register. + |
+
403 Forbidden + |
+InArrearOrInsufficientBalance + |
+The subscriber owes fees or the account balance is insufficient, and the subscriber does not have the permission to perform an operation. + |
+Top up the account. + |
+
403 Forbidden + |
+InsufficientStorageSpace + |
+Insufficient storage space. + |
+If the quota is exceeded, increase quota or delete some objects. + |
+
403 Forbidden + |
+InvalidAccessKeyId + |
+The access key ID provided by the customer does not exist in the system. + |
+Provide a correct access key ID. + |
+
403 Forbidden + |
+RequestTimeTooSkewed + |
+The request time and the server's time differ a lot. + |
+Check whether the difference between the client time and the current time is too large. + |
+
403 Forbidden + |
+SignatureDoesNotMatch + |
+The provided signature in the request does not match the signature calculated by OBS. + |
+Check your secret access key and signature calculation method. + |
+
403 Forbidden + |
+Unauthorized + |
+You have not been authenticated in real name. + |
+Authenticate your real name and try again. + |
+
404 Not Found + |
+NoSuchBucket + |
+The specified bucket does not exist. + |
+Create a bucket and perform the operation again. + |
+
404 Not Found + |
+NoSuchBucketPolicy + |
+No bucket policy exists. + |
+Configure a bucket policy. + |
+
404 Not Found + |
+NoSuchCORSConfiguration + |
+No CORS configuration exists. + |
+Configure CORS first. + |
+
404 Not Found + |
+NoSuchCustomDomain + |
+The requested user domain does not exist. + |
+Set a user domain first. + |
+
404 Not Found + |
+NoSuchKey + |
+The specified key does not exist. + |
+Upload the object first. + |
+
404 Not Found + |
+NoSuchLifecycleConfiguration + |
+The requested lifecycle rule does not exist. + |
+Configure a lifecycle rule first. + |
+
404 Not Found + |
+NoSuchUpload + |
+The specified multipart upload does not exist. The upload ID does not exist or the multipart upload job has been aborted or completed. + |
+Use the existing part or reinitialize the part. + |
+
404 Not Found + |
+NoSuchVersion + |
+The specified version ID does not match any existing version. + |
+Use a correct version ID. + |
+
404 Not Found + |
+NoSuchWebsiteConfiguration + |
+The requested website does not exist. + |
+Configure the website first. + |
+
405 Method Not Allowed + |
+MethodNotAllowed + |
+The specified method is not allowed against the requested resource. +The message "Specified method is not supported." is returned. + |
+The method is not allowed. + |
+
408 Request Timeout + |
+RequestTimeout + |
+No read or write operation has been performed within the timeout period of the socket connection between the user and the server. + |
+Check the network and try again, or contact technical support. + |
+
409 Conflict + |
+BucketAlreadyExists + |
+The requested bucket name already exists. The bucket namespace is shared by all users of OBS. Select another name and retry. + |
+Try another bucket name. + |
+
409 Conflict + |
+BucketAlreadyOwnedByYou + |
+Your previous request for creating the named bucket succeeded and you already own it. + |
+You do not need to create the bucket again. + |
+
409 Conflict + |
+BucketNotEmpty + |
+The bucket that you tried to delete is not empty. + |
+Delete the objects in the bucket and then delete the bucket. + |
+
409 Conflict + |
+FsObjectConflict + |
+File upload or creation failed. + |
+Check the file creation rule. For example, check whether you are overwriting files when overwrite is not allowed, or whether you are uploading a file to a file (taking this file as a directory) under POSIX semantics. + |
+
409 Conflict + |
+OperationAborted + |
+A conflicting operation is being performed on this resource. Retry later. + |
+Try again later. + |
+
409 Conflict + |
+ServiceNotSupported + |
+The request method is not supported by the server. + |
+Not supported by the server. Contact technical support. + |
+
411 Length Required + |
+MissingContentLength + |
+The HTTP header Content-Length is not provided. + |
+Provide the Content-Length header. + |
+
412 Precondition Failed + |
+PreconditionFailed + |
+At least one of the specified preconditions is not met. + |
+Modify according to the condition prompt in the returned message body. + |
+
416 Client Requested Range Not Satisfiable + |
+InvalidRange + |
+The requested range cannot be obtained. + |
+Retry with the correct range. + |
+
500 Internal Server Error + |
+InternalError + |
+An internal error occurs. Retry later. + |
+Contact the technical support. + |
+
501 Not Implemented + |
+ServiceNotImplemented + |
+The request method is not implemented by the server. + |
+Not supported currently. Contact the technical support. + |
+
503 Service Unavailable + |
+ServiceUnavailable + |
+The server is overloaded or has internal errors. + |
+Try again later or contact the technical support. + |
+
503 Service Unavailable + |
+SlowDown + |
+Too frequent requests. Reduce your request frequency. + |
+Reduce your request frequency. + |
+
After you successfully call an API in an instance of ObsClient, an instance of the HeaderResponse class (or of its sub-class) will be returned.
+It contains information about HTTP/HTTPS response headers.
+Sample code for processing public response headers:
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 | // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(ak, sk, endPoint); +HeaderResponse response = obsClient.createBucket("bucketname"); + +// Obtain the request ID from the common response headers. +System.out.println("\t" + response.getRequestId()); + +obsClient.close(); + |
You can obtain the default log configuration file log4j2.xml from the OBS Java SDK package, and then modify to customize the file.
+The log path of OBS Java SDK is specified in log4j2.xml. Logs are saved in the path represented by system variable user.dir of JDK by default. In general, there are three logs files as follows:
+ +File Name + |
+Description + |
+
|---|---|
OBS-SDK.interface_north.log + |
+Northbound log file, which saves the logs about the communication between OBS Java SDK and third-party applications of users. + |
+
OBS-SDK.interface_south.log + |
+Southbound log file, which saves the logs about the communication between OBS Java SDK and the OBS server. + |
+
OBS-SDK.access.log + |
+Run log file of the OBS server. + |
+
The SDK log format is: Log time|Thread number|Log level|Log content. The following are example logs:
+#Southbound logs +2017-08-21 17:40:07 133|main|INFO |HttpClient cost 157 ms to apply http request +2017-08-21 17:40:07 133|main|INFO |Received expected response code: true +2017-08-21 17:40:07 133|main|INFO |expected code(s): [200, 204]. + +#Northbound logs +2017-08-21 17:40:06 820|main|INFO |Storage|1|HTTP+XML|ObsClient||||2017-08-21 17:40:05|2017-08-21 17:40:06|||0| +2017-08-21 17:40:07 136|main|INFO |Storage|1|HTTP+XML|setObjectAcl||||2017-08-21 17:40:06|2017-08-21 17:40:07|||0| +2017-08-21 17:40:07 137|main|INFO |ObsClient [setObjectAcl] cost 312 ms+
When current logs cannot be used to troubleshoot system faults, you can change the log level to obtain more information. You can obtain the most information in TRACE logs and the least information in ERROR logs.
+Log level description:
+The following sample code shows how to set different levels for the southbound logs, northbound logs, and OBS server run logs. (For details about log configuration, see configuration file log4j2.xml.)
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 +11 +12 +13 +14 | <!-- north log --> +<Logger name="com.obs.services.AbstractClient" level="INFO" additivity="false"> + <AppenderRef ref="NorthInterfaceLogAppender" /> +</Logger> + +<!-- south log --> +<Logger name="com.obs.services.internal.RestStorageService" level="WARN" additivity="false"> + <AppenderRef ref="SouthInterfaceLogAppender" /> +</Logger> + +<!-- access log --> +<Logger name="com.obs.log.AccessLogger" level="ERROR" additivity="false"> + <AppenderRef ref="AccessLogAppender" /> +</Logger> + |
SDK custom exceptions (ObsException), thrown by ObsClient, are inherited from class java.lang.RuntimeException. Exceptions are usually OBS server errors, including OBS error codes and error information. This facilitates users to locate problems and troubleshot faults.
+ObsException contains the following error information:
+To do this, perform the following steps:
+SDK uses the maxErrorRetry parameter configured in Creating and Configuring an OBS Client to retry. The default value for retry times is 3. 0 to 5 is recommended.
+If the network connection is abnormal or the server returns the 5XX error when an ObsClient API is called, the SDK performs an exponential backoff retry.
+
After a bucket is configured to work in static website hosting mode, you can use the following method to combine the static website access address of the bucket.
+https://bucket name.static website hosting domain name
+If the uploaded object is set to be read by anonymous users, anonymous users can download the object through the object URL directly. Methods to obtain the object URL are as follows:
+Method 1: Query by calling the API. After an object is uploaded using the ObsClient API, PutObjectResult is returned. You can call getObjectUrl to obtain the URL of the uploaded object. The sample code is as follows:
+1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +10 | // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +// Create an ObsClient instance. +ObsClient obsClient = new ObsClient(ak, sk, endPoint); +// Call putObject to upload the object and obtain the return result. +PutObjectResult result = obsClient.putObject("bucketname", "objectname", new File("localfile")); +// Read the URL of the uploaded object. +System.out.println("\t" + result.getObjectUrl()); + |
Method 2: Assemble the URL in the format of https://Bucket name.Domain name/Directory level/Object name.
+
If a file exceeds 100 MB, you are advised to upload the file using multipart upload.
+Multipart upload refers to splitting an object into multiple parts and uploading them separately. Each part is a contiguous portion of the object's data. You can upload parts in any sequence. A part can be reloaded after an upload failure, without affecting other parts. Uploading multiple parts of an object using multiple threads concurrently can greatly improve the transmission efficiency.
+For code examples, see Multipart Upload.
+In a multipart upload, you can specify a part of the file to be uploaded by performing the following steps:
+For details, see Multipart Upload.
+In a multipart download, you can specify the range of data to be downloaded. The procedure is as follows:
+For details, see Downloading an Object - Range-Based.
+After the upload is complete, you can call ObsClient.getObjectMetadata to obtain the size and last modification time of the newly uploaded object and compare them with those of the overwritten object.
+If the sizes are the same and the last modification time of the new object is later than that of the overwritten object, the upload succeeded. Otherwise, the upload failed.
+For details about how to call ObsClient.getObjectMetadata, see Obtaining Object Metadata.
+If the object is encrypted with SSE-KMS, the server automatically decrypts the object when you use the URL of the object to download it.
+If the object is encrypted with SSE-C, you cannot access the object directly through a web browser because a request header is required for decryption. If you use code to download the encrypted object, configure the header by referring to Code Example: Downloading an Object Encrypted Using SSE-C.
+
Accessing a server-side encrypted object requires the HTTPS protocol.
+Sample code of generating an SSE-C encryption key and its MD5 value:
+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 | import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SseCTool { + public static void main(String[] args) { + // Below is an encryption key example. The key can be changed as needed, but it must be 32 characters long (a 256-bit string). + String keyString = System.getenv("ACCESS_KEY_ID"); + // Compute the x-obs-server-side-encryption-customer-key header. + String customerKey = toBase64String(keyString.getBytes(Charset.forName("UTF-8"))); + System.out.println("customer key is : " + customerKey); + + // Compute the x-obs-server-side-encryption-customer-key-MD5 header. + String customerKeyMD5 = computeMD5(fromBase64(customerKey)); + System.out.println("md5 for customer key is : " + customerKeyMD5); + } + + // Compute the Base64 character string. + public static String toBase64String(byte[] data) { + java.util.Base64.Encoder encoder = java.util.Base64.getEncoder(); + return new String(encoder.encode(data), Charset.forName("UTF-8")); + } + + // Compute the MD5 character string. + public static String computeMD5(byte[] b64Data) { + try { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.update(b64Data); + + byte[] byteArray = md5.digest(); + + return toBase64String(byteArray); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return ""; + } + + } + + public static byte[] fromBase64(String b64Data) { + java.util.Base64.Decoder decoder = java.util.Base64.getDecoder(); + return decoder.decode(b64Data.getBytes(Charset.forName("UTF-8"))); + } +} + |
No.
+Currently, the SDK does not provide such APIs. You need to encapsulate the service codes for uploading, downloading, or copying objects in a batch by yourself. The procedure is as follows:
+Sample code:
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 | // Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID. +// Obtain an AK/SK pair on the management console. +String ak = System.getenv("ACCESS_KEY_ID"); +String sk = System.getenv("SECRET_ACCESS_KEY_ID"); +final String bucketName = "bucketname"; +// Define the prefix of objects in a bucket. +final String objectPre = "object/"; +// Folder to be uploaded +final String localDirPath = "localDirPath"; +final List<File> list = new ArrayList<>(); +// Scan all objects in the folder. +static void listFiles(File file){ + File[] fs = file.listFiles(); + assert fs != null; + if (fs.length < 1){ + // If an empty folder needs to be uploaded, add it to the list. + list.add(file); + }else{ + for (File f:fs){ + if (f.isDirectory()){ + listFiles(f); + } + if (f.isFile()){ + // Add objects to be uploaded to the list. + list.add(f); + } + } + } +} +// Traverse the folder to be uploaded and obtain all objects to be uploaded. +File file = new File(localDirPath); +listFiles(file); + +// Create an instance of ObsClient. +final ObsClient obsClient = new ObsClient(ak, sk, endPoint); + +// Initialize the thread pool. +ExecutorService executorService = Executors.newFixedThreadPool(20); + +// Concurrently upload parts. +for (File f:list){ + executorService.execute(() -> { + if (f.isDirectory()){ + // For empty folders, create empty folder objects in the bucket. + String remoteObjectKey = objectPre + f.getPath().substring(localDirPath.length() + 1) + "/"; + obsClient.putObject(bucketName, remoteObjectKey, new ByteArrayInputStream(new byte[0])); + }else{ + String remoteObjectKey = objectPre + f.getPath().substring(localDirPath.length() + 1); + obsClient.putObject(bucketName, remoteObjectKey, new File(f.getPath())); + } + }); +} + +// Wait until the upload is complete. +executorService.shutdown(); +while (!executorService.isTerminated()) +{ + try + { + executorService.awaitTermination(5, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } +} +// Close ObsClient. +try { + obsClient.close(); +} catch (IOException e) { + e.printStackTrace(); +} + |
You can use multiple threads to concurrently upload, download, and copy data to improve efficiency.
+Multipurpose Internet Mail Extensions (MIME) type is a standard way of describing a data type. The MIME type is passed in the Content-Type header.
+
If you do not specify Content-Type when uploading an object, the SDK determines the object type based on the suffix of the specified object name and automatically assigns a value to Content-Type.
+Content-Type indicates the type of data to send or receive and determine the form and encoding method browsers will use to display data (mainly custom client files or media files). If no content type is specified, the type will be generated based on the file name extension. If there is no extension, the content type is application/octet-stream by default.
+The commonly used content types are given in the table below.
+ +File Name Extension + |
+Content-Type(Mime-Type) + |
+File Name Extension + |
+Content-Type(Mime-Type) + |
+
|---|---|---|---|
.* (binary stream, unknown file type) + |
+application/octet-stream + |
+.tif + |
+image/tiff + |
+
.a11 + |
+application/x-a11 + |
+.acp + |
+audio/x-mei-aac + |
+
.ai + |
+application/postscript + |
+.aif + |
+audio/aiff + |
+
.aifc + |
+audio/aiff + |
+.aiff + |
+audio/aiff + |
+
.anv + |
+application/x-anv + |
+.apk + |
+application/vnd.android.package-archive + |
+
.asa + |
+text/asa + |
+.asf + |
+video/x-ms-asf + |
+
.asp + |
+text/asp + |
+.asx + |
+video/x-ms-asf + |
+
.au + |
+audio/basic + |
+.avi + |
+video/avi + |
+
.awf + |
+application/vnd.adobe.workflow + |
+.biz + |
+text/xml + |
+
.bmp + |
+application/x-bmp + |
+.bot + |
+application/x-bot + |
+
.c4t + |
+application/x-c4t + |
+.c90 + |
+application/x-c90 + |
+
.cal + |
+application/x-cals + |
+.cat + |
+application/vnd.ms-pki.seccat + |
+
.cdf + |
+application/x-netcdf + |
+.cdr + |
+application/x-cdr + |
+
.cel + |
+application/x-cel + |
+.cer + |
+application/x-x509-ca-cert + |
+
.cg4 + |
+application/x-g4 + |
+.cgm + |
+application/x-cgm + |
+
.cit + |
+application/x-cit + |
+.class + |
+java/ + |
+
.cml + |
+text/xml + |
+.cmp + |
+application/x-cmp + |
+
.cmx + |
+application/x-cmx + |
+.cot + |
+application/x-cot + |
+
.crl + |
+application/pkix-crl + |
+.crt + |
+application/x-x509-ca-cert + |
+
.csi + |
+application/x-csi + |
+.css + |
+text/css + |
+
.csv + |
+text/csv + |
+.cut + |
+application/x-cut + |
+
.dbf + |
+application/x-dbf + |
+.dbm + |
+application/x-dbm + |
+
.dbx + |
+application/x-dbx + |
+.dcd + |
+text/xml + |
+
.dcx + |
+application/x-dcx + |
+.der + |
+application/x-x509-ca-cert + |
+
.dgn + |
+application/x-dgn + |
+.dib + |
+application/x-dib + |
+
.dll + |
+application/x-msdownload + |
+.doc + |
+application/msword + |
+
.docx + |
+application/vnd.openxmlformats-officedocument.wordprocessingml.document + |
+.dot + |
+application/msword + |
+
.dotx + |
+application/vnd.openxmlformats-officedocument.wordprocessingml.template + |
+.drw + |
+application/x-drw + |
+
.dtd + |
+text/xml + |
+.dwf + |
+Model/vnd.dwf + |
+
.dwf + |
+application/x-dwf + |
+.dwg + |
+application/x-dwg + |
+
.dxb + |
+application/x-dxb + |
+.dxf + |
+application/x-dxf + |
+
.edn + |
+application/vnd.adobe.edn + |
+.emf + |
+application/x-emf + |
+
.eml + |
+message/rfc822 + |
+.ent + |
+text/xml + |
+
.epi + |
+application/x-epi + |
+.eps + |
+application/x-ps + |
+
.eps + |
+application/postscript + |
+.etd + |
+application/x-ebx + |
+
.exe + |
+application/x-msdownload + |
+.fax + |
+image/fax + |
+
.fdf + |
+application/vnd.fdf + |
+.fif + |
+application/fractals + |
+
.fo + |
+text/xml + |
+.frm + |
+application/x-frm + |
+
.g4 + |
+application/x-g4 + |
+.gbr + |
+application/x-gbr + |
+
. + |
+application/x- + |
+.gif + |
+image/gif + |
+
.gl2 + |
+application/x-gl2 + |
+.gp4 + |
+application/x-gp4 + |
+
.hgl + |
+application/x-hgl + |
+.hmr + |
+application/x-hmr + |
+
.hpg + |
+application/x-hpgl + |
+.hpl + |
+application/x-hpl + |
+
.hqx + |
+application/mac-binhex40 + |
+.hrf + |
+application/x-hrf + |
+
.hta + |
+application/hta + |
+.htc + |
+text/x-component + |
+
.htm + |
+text/html + |
+.html + |
+text/html + |
+
.htt + |
+text/webviewhtml + |
+.htx + |
+text/html + |
+
.icb + |
+application/x-icb + |
+.ico + |
+image/x-icon + |
+
.ico + |
+application/x-ico + |
+.iff + |
+application/x-iff + |
+
.ig4 + |
+application/x-g4 + |
+.igs + |
+application/x-igs + |
+
.iii + |
+application/x-iphone + |
+.img + |
+application/x-img + |
+
.ins + |
+application/x-internet-signup + |
+.ipa + |
+application/vnd.iphone + |
+
.isp + |
+application/x-internet-signup + |
+.IVF + |
+video/x-ivf + |
+
.java + |
+java/* + |
+.jfif + |
+image/jpeg + |
+
.jpe + |
+image/jpeg + |
+.jpe + |
+application/x-jpe + |
+
.jpeg + |
+image/jpeg + |
+.jpg + |
+image/jpeg + |
+
.jpg + |
+application/x-jpg + |
+.js + |
+application/x-javascript + |
+
.jsp + |
+text/html + |
+.la1 + |
+audio/x-liquid-file + |
+
.lar + |
+application/x-laplayer-reg + |
+.latex + |
+application/x-latex + |
+
.lavs + |
+audio/x-liquid-secure + |
+.lbm + |
+application/x-lbm + |
+
.lmsff + |
+audio/x-la-lms + |
+.ls + |
+application/x-javascript + |
+
.ltr + |
+application/x-ltr + |
+.m1v + |
+video/x-mpeg + |
+
.m2v + |
+video/x-mpeg + |
+.m3u + |
+audio/mpegurl + |
+
.m4e + |
+video/mpeg4 + |
+.mac + |
+application/x-mac + |
+
.man + |
+application/x-troff-man + |
+.math + |
+text/xml + |
+
.mdb + |
+application/msaccess + |
+.mdb + |
+application/x-mdb + |
+
.mfp + |
+application/x-shockwave-flash + |
+.mht + |
+message/rfc822 + |
+
.mhtml + |
+message/rfc822 + |
+.mi + |
+application/x-mi + |
+
.mid + |
+audio/mid + |
+.midi + |
+audio/mid + |
+
.mil + |
+application/x-mil + |
+.mml + |
+text/xml + |
+
.mnd + |
+audio/x-musicnet-download + |
+.mns + |
+audio/x-musicnet-stream + |
+
.mocha + |
+application/x-javascript + |
+.mov + |
+video/quicktime + |
+
.movie + |
+video/x-sgi-movie + |
+mp1 + |
+audio/mp1 + |
+
.mp2 + |
+audio/mp2 + |
+.mp2v + |
+video/mpeg + |
+
.mp3 + |
+audio/mp3 + |
+.mp4 + |
+video/mp4 + |
+
.mpa + |
+video/x-mpg + |
+.mpd + |
+application/vnd.ms-project + |
+
.mpe + |
+video/x-mpeg + |
+.mpeg + |
+video/mpg + |
+
.mpg + |
+video/mpg + |
+.mpga + |
+audio/rn-mpeg + |
+
.mpp + |
+application/vnd.ms-project + |
+.mps + |
+video/x-mpeg + |
+
.mpt + |
+application/vnd.ms-project + |
+.mpv + |
+video/mpg + |
+
.mpv2 + |
+video/mpeg + |
+.mpw + |
+application/vnd.ms-project + |
+
.mpx + |
+application/vnd.ms-project + |
+.mtx + |
+text/xml + |
+
.mxp + |
+application/x-mmxp + |
+.net + |
+image/pnetvue + |
+
.nrf + |
+application/x-nrf + |
+.nws + |
+message/rfc822 + |
+
.odc + |
+text/x-ms-odc + |
+.out + |
+application/x-out + |
+
.p10 + |
+application/pkcs10 + |
+.p12 + |
+application/x-pkcs12 + |
+
.p7b + |
+application/x-pkcs7-certificates + |
+.p7c + |
+application/pkcs7-mime + |
+
.p7m + |
+application/pkcs7-mime + |
+.p7r + |
+application/x-pkcs7-certreqresp + |
+
.p7s + |
+application/pkcs7-signature + |
+.pc5 + |
+application/x-pc5 + |
+
.pci + |
+application/x-pci + |
+.pcl + |
+application/x-pcl + |
+
.pcx + |
+application/x-pcx + |
+application/pdf + |
+|
.pdb + |
+chemical/x-pdb + |
+.pdx + |
+application/vnd.adobe.pdx + |
+
.pfx + |
+application/x-pkcs12 + |
+.pgl + |
+application/x-pgl + |
+
.pic + |
+application/x-pic + |
+.pko + |
+application/vnd.ms-pki.pko + |
+
.pl + |
+application/x-perl + |
+.plg + |
+text/html + |
+
.pls + |
+audio/scpls + |
+.plt + |
+application/x-plt + |
+
.png + |
+image/png + |
+.png + |
+application/x-png + |
+
.pot + |
+application/vnd.ms-powerpoint + |
+.potx + |
+application/vnd.openxmlformats-officedocument.presentationml.template + |
+
.ppa + |
+application/vnd.ms-powerpoint + |
+.ppm + |
+application/x-ppm + |
+
.pps + |
+application/vnd.ms-powerpoint + |
+.ppsx + |
+application/vnd.openxmlformats-officedocument.presentationml.slideshow + |
+
.ppt + |
+application/vnd.ms-powerpoint + |
+.ppt + |
+application/x-ppt + |
+
. pptx + |
+application/vnd.openxmlformats-officedocument.presentationml.presentation + |
+.pr + |
+application/x-pr + |
+
.prf + |
+application/pics-rules + |
+.prn + |
+application/x-prn + |
+
.prt + |
+application/x-prt + |
+.ps + |
+application/x-ps + |
+
.ps + |
+application/postscript + |
+.ptn + |
+application/x-ptn + |
+
.pwz + |
+application/vnd.ms-powerpoint + |
+.r3t + |
+text/vnd.rn-realtext3d + |
+
.ra + |
+audio/vnd.rn-realaudio + |
+.ram + |
+audio/x-pn-realaudio + |
+
.ras + |
+application/x-ras + |
+.rat + |
+application/rat-file + |
+
.rdf + |
+text/xml + |
+.rec + |
+application/vnd.rn-recording + |
+
.red + |
+application/x-red + |
+.rgb + |
+application/x-rgb + |
+
.rjs + |
+application/vnd.rn-realsystem-rjs + |
+.rjt + |
+application/vnd.rn-realsystem-rjt + |
+
.rlc + |
+application/x-rlc + |
+.rle + |
+application/x-rle + |
+
.rm + |
+application/vnd.rn-realmedia + |
+.rmf + |
+application/vnd.adobe.rmf + |
+
.rmi + |
+audio/mid + |
+.rmj + |
+application/vnd.rn-realsystem-rmj + |
+
.rmm + |
+audio/x-pn-realaudio + |
+.rmp + |
+application/vnd.rn-rn_music_package + |
+
.rms + |
+application/vnd.rn-realmedia-secure + |
+.rmvb + |
+application/vnd.rn-realmedia-vbr + |
+
.rmx + |
+application/vnd.rn-realsystem-rmx + |
+.rnx + |
+application/vnd.rn-realplayer + |
+
.rp + |
+image/vnd.rn-realpix + |
+.rpm + |
+audio/x-pn-realaudio-plugin + |
+
.rsml + |
+application/vnd.rn-rsml + |
+.rt + |
+text/vnd.rn-realtext + |
+
.rtf + |
+application/msword + |
+.rtf + |
+application/x-rtf + |
+
.rv + |
+video/vnd.rn-realvideo + |
+.sam + |
+application/x-sam + |
+
.sat + |
+application/x-sat + |
+.sdp + |
+application/sdp + |
+
.sdw + |
+application/x-sdw + |
+.sis + |
+application/vnd.symbian.install + |
+
.sisx + |
+application/vnd.symbian.install + |
+.sit + |
+application/x-stuffit + |
+
.slb + |
+application/x-slb + |
+.sld + |
+application/x-sld + |
+
.sldx + |
+application/vnd.openxmlformats-officedocument.presentationml.slide + |
+.slk + |
+drawing/x-slk + |
+
.smi + |
+application/smil + |
+.smil + |
+application/smil + |
+
.smk + |
+application/x-smk + |
+.snd + |
+audio/basic + |
+
.sol + |
+text/plain + |
+.sor + |
+text/plain + |
+
.spc + |
+application/x-pkcs7-certificates + |
+.spl + |
+application/futuresplash + |
+
.spp + |
+text/xml + |
+.ssm + |
+application/streamingmedia + |
+
.sst + |
+application/vnd.ms-pki.certstore + |
+.stl + |
+application/vnd.ms-pki.stl + |
+
.stm + |
+text/html + |
+.sty + |
+application/x-sty + |
+
.svg + |
+image/svg+xml + |
+.swf + |
+application/x-shockwave-flash + |
+
.tdf + |
+application/x-tdf + |
+.tg4 + |
+application/x-tg4 + |
+
.tga + |
+application/x-tga + |
+.tif + |
+image/tiff + |
+
.tif + |
+application/x-tif + |
+.tiff + |
+image/tiff + |
+
.tld + |
+text/xml + |
+.top + |
+drawing/x-top + |
+
.torrent + |
+application/x-bittorrent + |
+.tsd + |
+text/xml + |
+
.txt + |
+text/plain + |
+.uin + |
+application/x-icq + |
+
.uls + |
+text/iuls + |
+.vcf + |
+text/x-vcard + |
+
.vda + |
+application/x-vda + |
+.vdx + |
+application/vnd.visio + |
+
.vml + |
+text/xml + |
+.vpg + |
+application/x-vpeg005 + |
+
.vsd + |
+application/vnd.visio + |
+.vsd + |
+application/x-vsd + |
+
.vss + |
+application/vnd.visio + |
+.vst + |
+application/vnd.visio + |
+
.vst + |
+application/x-vst + |
+.vsw + |
+application/vnd.visio + |
+
.vsx + |
+application/vnd.visio + |
+.vtx + |
+application/vnd.visio + |
+
.vxml + |
+text/xml + |
+.wav + |
+audio/wav + |
+
.wax + |
+audio/x-ms-wax + |
+.wb1 + |
+application/x-wb1 + |
+
.wb2 + |
+application/x-wb2 + |
+.wb3 + |
+application/x-wb3 + |
+
.wbmp + |
+image/vnd.wap.wbmp + |
+.wiz + |
+application/msword + |
+
.wk3 + |
+application/x-wk3 + |
+.wk4 + |
+application/x-wk4 + |
+
.wkq + |
+application/x-wkq + |
+.wks + |
+application/x-wks + |
+
.wm + |
+video/x-ms-wm + |
+.wma + |
+audio/x-ms-wma + |
+
.wmd + |
+application/x-ms-wmd + |
+.wmf + |
+application/x-wmf + |
+
.wml + |
+text/vnd.wap.wml + |
+.wmv + |
+video/x-ms-wmv + |
+
.wmx + |
+video/x-ms-wmx + |
+.wmz + |
+application/x-ms-wmz + |
+
.wp6 + |
+application/x-wp6 + |
+.wpd + |
+application/x-wpd + |
+
.wpg + |
+application/x-wpg + |
+.wpl + |
+application/vnd.ms-wpl + |
+
.wq1 + |
+application/x-wq1 + |
+.wr1 + |
+application/x-wr1 + |
+
.wri + |
+application/x-wri + |
+.wrk + |
+application/x-wrk + |
+
.ws + |
+application/x-ws + |
+.ws2 + |
+application/x-ws + |
+
.wsc + |
+text/scriptlet + |
+.wsdl + |
+text/xml + |
+
.wvx + |
+video/x-ms-wvx + |
+.xap + |
+application/x-silverlight-app + |
+
.x_b + |
+application/x-x_b + |
+.xdp + |
+application/vnd.adobe.xdp + |
+
.xdr + |
+text/xml + |
+.xfd + |
+application/vnd.adobe.xfd + |
+
.xfdf + |
+application/vnd.adobe.xfdf + |
+.xhtml + |
+text/html + |
+
.xls + |
+application/vnd.ms-excel + |
+.xls + |
+application/x-xls + |
+
.xlsx + |
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + |
+.xltx + |
+application/vnd.openxmlformats-officedocument.spreadsheetml.template + |
+
.xlw + |
+application/x-xlw + |
+.xml + |
+text/xml + |
+
.xpl + |
+audio/scpls + |
+.xq + |
+text/xml + |
+
.xql + |
+text/xml + |
+.xquery + |
+text/xml + |
+
.xsd + |
+text/xml + |
+.xsl + |
+text/xml + |
+
.xslt + |
+text/xml + |
+.xwd + |
+application/x-xwd + |
+
.x_t + |
+application/x-x_t + |
+.yaml + |
+text/vnd.yaml + |
+
.yml + |
+text/vnd.yml + |
+.webp + |
+image/webp + |
+
.tar + |
+application/x-tar + |
+.zip + |
+application/zip + |
+
Release Date + |
+What's New + |
+
|---|---|
2025-03-30 + |
+This is the first official release. + |
+
Client-side encryption is a process where data is encrypted using the selected encryption method and information on your local PC before it is transmitted to an OBS server. During this process, the encryption method used and necessary information required for decryption will be stored in object metadata. During a download, the OBS SDK decrypts the data based on the key provided and the information stored in object metadata, and then returns the decrypted data.
+
The OBS SDK for Java offers two cipher suite generators: CTRCipherGenerator based on AES-CTR, and CtrRSACipherGenerator based on RSA and AES-CTR.
+If CTRCipherGenerator is used to upload objects, you need to provide a data key. The SDK then randomly generates an initial value for each object and uses the data key and initial value to encrypt the object. After the encryption, the SDK uploads the encrypted object to OBS and stores its initial value in object metadata. To download this object, you need to use the same data key used for upload. The SDK automatically obtains the initial value from object metadata, uses the data key provided and initial value to decrypt the object, and returns the decrypted data. If a different data key is provided for download, the SDK returns an unavailable decrypted file.
+If CtrRSACipherGenerator is used to upload objects, you need to provide an RSA public key. The SDK then randomly generates a data key and initial value for each object and uses them to encrypt the object. After that, the SDK uploads the encrypted object to OBS and then uses the provided RSA key to encrypt the data key. The encrypted data key and initial value are stored in the object metadata. To download this object, you need to provide the corresponding RSA private key. The SDK then automatically obtains the data key and initial value stored in the object metadata and uses the provided RSA private key to decrypt the data key. If the provided private key does not match the public key used for upload, an error will be reported. After the data key is decrypted, the SDK uses the decrypted data key and initial value to decrypt the object and returns the decrypted data.
+CryptoObsClient is inherited from ObsClient. Except the APIs listed in the following table, all other APIs of CryptoObsClient are the same as those of ObsClient.
+ +API + |
+CryptoObsClient API Action + |
+
|---|---|
putObject + |
+Encrypts streams or files and then upload them to OBS. + |
+
getObject + |
+Returns the decrypted data streams. + |
+
The SDK saves the information required for decryption in the user-defined metadata of an object and does not back it up. If you modify the stored information, data cannot be decrypted. The following table describes the information required for decryption.
+ +Parameter + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|
encrypted-algorithm + |
+Yes + |
+Information about a cipher suite + |
+
encrypted-object-key + |
+Yes when CtrRSACipherGenerator is used + |
+Data key encrypted using an RSA key + |
+
encrypted-start + |
+Yes + |
+String of the Base64-encoded initial value used for encryption + |
+
master-key-info + |
+No + |
+Information about encryption keys + |
+
plaintext-sha256 + |
+No + |
+SHA-256 value of the object before being encrypted (not available for streaming uploads) + |
+
plaintext-content-length + |
+No + |
+Length of the object before being encrypted (not available for streaming uploads) + |
+
encrypted-sha256 + |
+No + |
+SHA-256 value of the object after being encrypted (not available for streaming uploads) + |
+
OBS SDK for Java provides two cipher suites for you to choose from.
+CtrRSACipherGenerator is inherited from CTRCipherGenerator but only requires you to provide an RSA public or private key to encrypt or decrypt the randomly generated data key.
+CTRCipherGenerator requires only one data key. This key is used to encrypt all objects.
+ +Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
privateKey + |
+PrivateKey + |
+Yes when decrypting objects (for example, getObject) + |
+Explanation: +RSA private key. +Default value: +None + |
+
publicKey + |
+PublicKey + |
+Yes for encryption (for example, putObject) + |
+Explanation: +RSA public key. +Default value: +None + |
+
masterKeyInfo + |
+String + |
+No + |
+Explanation: +Key information, which is stored in the user-defined metadata of objects to help you identify keys. You need to maintain the mappings between keys and masterKeyInfo on your own. +Default value: +None + |
+
secureRandom + |
+SecureRandom + |
+Yes + |
+Explanation: +Secure random number generator, which is used to randomly generate cryptoKeyBytes and cryptoIvBytes. +Default value: +None + |
+
needSha256 + |
+boolean + |
+No + |
+Explanation: +Whether to verify the SHA-256 value of the encrypted data and to add SHA-256 values calculated before and after the encryption to the user-defined metadata. + NOTE:
+To reduce memory overheads, the SDK uses streaming computing, which means that a file needs to be read and encrypted twice in a common upload and three times in a resumable upload. +Value range: +If need_sha256 is set to true, the SDK automatically calculates SHA-256 before and after the object is encrypted and saves the two values to the user-defined metadata of the object. In addition, the SDK adds the SHA-256 value of the encrypted object to the request header when sending a request to the server. After receiving the request, the server calculates the SHA-256 value of the object and checks the consistency between the calculated and the received values. If they are inconsistent, an error message is returned. +false: The SHA-256 value of the encrypted data is not verified. +Default value: +false + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
masterKeyInfo + |
+String + |
+No + |
+Explanation: +Key information, which is stored in the user-defined metadata of objects to help you identify cryptoKeyBytes. You need to maintain the mappings between cryptoKeyBytes and masterKeyInfo on your own. +Default value: +None + |
+
cryptoKeyBytes + |
+byte[] + |
+Yes + |
+Explanation: +Data key used for encrypting data. +Restrictions: +The value must be 32 bytes long. +Default value: +None + |
+
cryptoIvBytes + |
+byte[] + |
+No + |
+Explanation: +Initial value used for encrypting data. +Restrictions: +
Default value: +None + |
+
secureRandom + |
+SecureRandom + |
+Yes + |
+Explanation: +Secure random number generator, for use when either cryptoKeyBytes or cryptoIvBytes is missing. +Default value: +None + |
+
needSha256 + |
+boolean + |
+No + |
+Explanation: +Whether to verify the SHA-256 value of the encrypted data and to add SHA-256 values calculated before and after the encryption to the user-defined metadata. + NOTE:
+To reduce memory overheads, the SDK uses streaming computing, which means that a file needs to be read and encrypted twice in a common upload and three times in a resumable upload. +Value range: +If need_sha256 is set to true, the SDK automatically calculates SHA-256 before and after the object is encrypted and saves the two values to the user-defined metadata of the object. In addition, the SDK adds the SHA-256 value of the encrypted object to the request header when sending a request to the server. After receiving the request, the server calculates the SHA-256 value of the object and checks the consistency between the calculated and the received values. If they are inconsistent, an error message is returned. +false: The SHA-256 value of the encrypted data is not verified. +Default value: +false + |
+
CryptoObsClient is inherited from ObsClient. For its configuration details, see Creating and Configuring an OBS Client.
+Method
+CryptoObsClient(String accessKey, String secretKey, String endPoint, CTRCipherGenerator ctrCipherGenerator)
+Parameter + |
+Description + |
+Recommended Value + |
+
|---|---|---|
accessKey + |
+Explanation: +Access key ID (AK). +Default value: +An empty string, indicating an anonymous user. + |
+N/A + |
+
secretKey + |
+Explanation: +Secret access key (SK). +Default value: +An empty string, indicating an anonymous user. + |
+N/A + |
+
endPoint + |
+Explanation: +OBS server address. It consists of a protocol type, domain name, and port number, for example, https://your-endpoint:443. For security purposes, you are advised to use HTTPS. +Default value: +None + |
+N/A + |
+
ctrCipherGenerator + |
+Explanation: +Cipher suite used by the client. +Value range: + +Default value: +None + |
+N/A + |
+
Method + |
+Description + |
+
|---|---|
putObject + |
+Uploads an object. + |
+
getObject + |
+Downloads an object. + |
+
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 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 +100 +101 +102 +103 +104 | import com.obs.services.ObsConfiguration; +import com.obs.services.crypto.CTRCipherGenerator; +import com.obs.services.crypto.CryptoObsClient; +import com.obs.services.crypto.CtrRSACipherGenerator; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObsObject; +import com.obs.services.model.PutObjectResult; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; + +public class CtrRSACipherGeneratorDemo001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + CtrRSACipherGenerator ctrRSACipherGenerator = null; + try { + String examplePrivateKeyPath = "yourRSAPrivateKeyPath"; + String examplePublicKeyPath = "yourRSAPublicKeyPath"; + ObsConfiguration config = new ObsConfiguration(); + PrivateKey privateKeyObj = CtrRSACipherGenerator.importPKCS8PrivateKey(examplePrivateKeyPath); + PublicKey publicKeyObj = CtrRSACipherGenerator.importPublicKey(examplePublicKeyPath); + ctrRSACipherGenerator = + new CtrRSACipherGenerator( + "example_master_key_info", true, config.getSecureRandom(), privateKeyObj, publicKeyObj); + + } catch (IllegalArgumentException | IOException | NoSuchAlgorithmException | InvalidKeySpecException e) { + e.printStackTrace(); + } + assert ctrRSACipherGenerator != null; + // Create an ObsClient instance. + try (CryptoObsClient cryptoObsClient = new CryptoObsClient(ak, sk, securityToken, endPoint, ctrRSACipherGenerator)) { + String exampleBucketName = "example-bucket"; + String exampleObjectKey = "exampleObjectKey"; + String examplePlainTextFilePath = "examplePlainTextFilePath"; + String exampleDecryptedFilePath = "exampleDecryptedFilePath"; + PutObjectResult putObjectResult = + cryptoObsClient.putObject(exampleBucketName, exampleObjectKey, new File(examplePlainTextFilePath)); + System.out.println("HTTP Code: " + putObjectResult.getStatusCode()); + System.out.println("Etag: " + putObjectResult.getEtag()); + // The object is successfully encrypted on the client and then uploaded. + System.out.println("CtrRSACipherGeneratorDemo001 putObject successfully"); + + GetObjectRequest getObjectRequest = new GetObjectRequest(exampleBucketName, exampleObjectKey); + ObsObject obsObject = cryptoObsClient.getObject(getObjectRequest); + InputStream input = obsObject.getObjectContent(); + byte[] b = new byte[1024]; + FileOutputStream fileOutputStream = new FileOutputStream(exampleDecryptedFilePath); + int len; + while ((len = input.read(b)) != -1) { + fileOutputStream.write(b, 0, len); + } + fileOutputStream.close(); + input.close(); + + System.out.println("HTTP Code: " + obsObject.getMetadata().getStatusCode()); + // The object is successfully decrypted on the client and then downloaded. + System.out.println("CtrRSACipherGeneratorDemo001 getObject successfully"); + + // Check whether the file remains the same before encryption and after decryption. + byte[] plainTextFileSha256 = CTRCipherGenerator.getFileSha256Bytes(examplePlainTextFilePath); + byte[] decryptedFileSha256 = CTRCipherGenerator.getFileSha256Bytes(exampleDecryptedFilePath); + String plainTextFileSha256Base64Encoded = CTRCipherGenerator.getBase64Info(plainTextFileSha256); + String decryptedFileSha256Base64Encoded = CTRCipherGenerator.getBase64Info(decryptedFileSha256); + System.out.println("plainTextFileSha256 base64 encoded: " + plainTextFileSha256Base64Encoded); + System.out.println("decryptedFileSha256 base64 encoded: " + decryptedFileSha256Base64Encoded); + System.out.println( + "plainTextFileSha256 equals decryptedFileSha256 ? " + + decryptedFileSha256Base64Encoded.equals(plainTextFileSha256Base64Encoded)); + System.out.println("CtrRSACipherGeneratorDemo001 successfully"); + } catch (ObsException e) { + System.out.println("CtrRSACipherGeneratorDemo001 failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("CtrRSACipherGeneratorDemo001 putObject failed"); + // Print other error details. + e.printStackTrace(); + } + } +} + |
CTRCipherGenerator:
+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 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 | import com.obs.services.crypto.CTRCipherGenerator; +import com.obs.services.crypto.CryptoObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.GetObjectRequest; +import com.obs.services.model.ObsObject; +import com.obs.services.model.PutObjectResult; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +public class CTRCipherGeneratorDemo001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + CTRCipherGenerator ctrCipherGenerator = null; + try { + SecureRandom secureRandom = SecureRandom.getInstanceStrong(); + // Note that in Linux, using SecureRandom.getInstanceStrong() may block the thread in case of insufficient system entropy. In this case, you are advised to either use entropy addition methods or set SecureRandom in another way. + byte[] exampleMasterKey = new byte[CTRCipherGenerator.CRYPTO_KEY_BYTES_LEN]; + secureRandom.nextBytes(exampleMasterKey); + // Replace exampleMasterKey with the one you actually use. Make sure the key is 32 bytes and keep it properly. + ctrCipherGenerator = + new CTRCipherGenerator("example_master_key_info", exampleMasterKey, true, secureRandom); + } catch (IllegalArgumentException | NoSuchAlgorithmException e) { + e.printStackTrace(); + } + assert ctrCipherGenerator != null; + // Create an ObsClient instance. + try (CryptoObsClient cryptoObsClient = + new CryptoObsClient(ak, sk, securityToken, endPoint, ctrCipherGenerator)) { + String exampleBucketName = "example-bucket"; + String exampleObjectKey = "exampleObjectKey"; + String examplePlainTextFilePath = "examplePlainTextFilePath"; + String exampleDecryptedFilePath = "exampleDecryptedFilePath"; + PutObjectResult putObjectResult = + cryptoObsClient.putObject(exampleBucketName, exampleObjectKey, new File(examplePlainTextFilePath)); + System.out.println("HTTP Code: " + putObjectResult.getStatusCode()); + System.out.println("Etag: " + putObjectResult.getEtag()); + // The object is successfully encrypted on the client and then uploaded. + System.out.println("CTRCipherGeneratorDemo001 putObject successfully"); + + GetObjectRequest getObjectRequest = new GetObjectRequest(exampleBucketName, exampleObjectKey); + ObsObject obsObject = cryptoObsClient.getObject(getObjectRequest); + InputStream input = obsObject.getObjectContent(); + byte[] b = new byte[1024]; + FileOutputStream fileOutputStream = new FileOutputStream(exampleDecryptedFilePath); + int len; + while ((len = input.read(b)) != -1) { + fileOutputStream.write(b, 0, len); + } + fileOutputStream.close(); + input.close(); + + System.out.println("HTTP Code: " + obsObject.getMetadata().getStatusCode()); + // The object is successfully decrypted on the client and then downloaded. + System.out.println("CTRCipherGeneratorDemo001 getObject successfully"); + + // Check whether the file remains the same before encryption and after decryption. + byte[] plainTextFileSha256 = CTRCipherGenerator.getFileSha256Bytes(examplePlainTextFilePath); + byte[] decryptedFileSha256 = CTRCipherGenerator.getFileSha256Bytes(exampleDecryptedFilePath); + String plainTextFileSha256Base64Encoded = CTRCipherGenerator.getBase64Info(plainTextFileSha256); + String decryptedFileSha256Base64Encoded = CTRCipherGenerator.getBase64Info(decryptedFileSha256); + System.out.println("plainTextFileSha256 base64 encoded: " + plainTextFileSha256Base64Encoded); + System.out.println("decryptedFileSha256 base64 encoded: " + decryptedFileSha256Base64Encoded); + System.out.println( + "plainTextFileSha256 equals decryptedFileSha256 ? " + + decryptedFileSha256Base64Encoded.equals(plainTextFileSha256Base64Encoded)); + System.out.println("CTRCipherGeneratorDemo001 successfully"); + } catch (ObsException e) { + System.out.println("CTRCipherGeneratorDemo001 failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code: " + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message: " + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + } catch (Exception e) { + System.out.println("CTRCipherGeneratorDemo001 putObject failed"); + // Print other error details. + e.printStackTrace(); + } + } +} + |
When calling APIs, you may need to specify the account ID (DomainID) and user ID (UserID) in some requests. You need to obtain them from the console in advance. To obtain them from the console, do as follows:
+On the My Credentials page, view the account ID and user ID.
+This example limits the upload rate by specifying the x-obs-traffic-limit header. The SDK transparently transmits the header for the server to verify.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use a permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use a temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload a file. + // localfile indicates the path of the local file to be uploaded, in which the file name must be specified. + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectkey"); + request.setFile(new File("localfile")); + HashMap<String, String> userHeaders = new HashMap<>(); + // Specify x-obs-traffic-limit as the rate limit, in bit/s. 819200 (100 KB/s) is used in this example. + userHeaders.put("x-obs-traffic-limit","819200"); + request.setUserHeaders(userHeaders); + PutObjectResult putObjectResult = obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example limits the download rate by specifying the x-obs-traffic-limit header. The SDK transparently transmits the header for the server to verify.
+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 +49 +50 +51 +52 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.ObsObject; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +public class GetObject001 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use a permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use a temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Download an object. + GetObjectRequest request = new GetObjectRequest("examplebucket", "objectname"); + HashMap<String, String> userHeaders = new HashMap<>(); + // Specify x-obs-traffic-limit as the rate limit, in bit/s. 819200 (100 KB/s) is used in this example. + userHeaders.put("x-obs-traffic-limit","819200"); + request.setUserHeaders(userHeaders); + ObsObject obsObject = obsClient.getObject(request); + } catch (ObsException e) { + System.out.println("getObjectContent failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("getObjectContent failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |
This example uploads localfile to examplebucket as objectkey and sets the referer header to https://example.com*.
+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 +49 +50 +51 +52 +53 +54 +55 +56 | import com.obs.services.ObsClient; +import com.obs.services.exception.ObsException; +import com.obs.services.model.PutObjectRequest; +import java.io.File; +public class PutObject004 { + public static void main(String[] args) { + // Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + String ak = System.getenv("ACCESS_KEY_ID"); + String sk = System.getenv("SECRET_ACCESS_KEY_ID"); + // (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. + // Obtain an AK/SK pair and a security token using environment variables or import them in other ways. + // String securityToken = System.getenv("SECURITY_TOKEN"); + // Enter the endpoint corresponding to the region where the bucket is located. + String endPoint = "https://your-endpoint"; + // Obtain an endpoint using environment variables or import it in other ways. + //String endPoint = System.getenv("ENDPOINT"); + + // Create an ObsClient instance. + // Use a permanent AK/SK pair to initialize the client. + ObsClient obsClient = new ObsClient(ak, sk,endPoint); + // Use a temporary AK/SK pair and security token to initialize the client. + // ObsClient obsClient = new ObsClient(ak, sk, securityToken, endPoint); + + try { + // Upload a file. + // localfile indicates the path of the local file to be uploaded, in which the file name must be specified. + PutObjectRequest request = new PutObjectRequest(); + request.setBucketName("examplebucket"); + request.setObjectKey("objectkey"); + request.setFile(new File("localfile")); + HashMap<String, String> userHeaders = new HashMap<>(); + // Specify the referer header when uploading an object. + userHeaders.put("referer","https://example.com*"); + request.setUserHeaders(userHeaders); + PutObjectResult putObjectResult = obsClient.putObject(request); + System.out.println("putObject successfully"); + } catch (ObsException e) { + System.out.println("putObject failed"); + // Request failed. Print the HTTP status code. + System.out.println("HTTP Code:" + e.getResponseCode()); + // Request failed. Print the server-side error code. + System.out.println("Error Code:" + e.getErrorCode()); + // Request failed. Print the error details. + System.out.println("Error Message:" + e.getErrorMessage()); + // Request failed. Print the request ID. + System.out.println("Request ID:" + e.getErrorRequestId()); + System.out.println("Host ID:" + e.getErrorHostId()); + e.printStackTrace(); + } catch (Exception e) { + System.out.println("putObject failed"); + // Print other error information. + e.printStackTrace(); + } + } +} + |