Help Center/ Object Storage Service/ SDK Reference/ Java/ API Overview (SDK for Java)
Updated on 2024-12-11 GMT+08:00

API Overview (SDK for Java)

Bucket APIs

Table 1 lists the bucket-related APIs.

Table 1 Bucket APIs

API

Method

Function

Source Code Example

Creating a Bucket (SDK for Java)

obsClient.createBucket(CreateBucketRequest request)

Creates a bucket and configures the storage class, region, and access permissions for the bucket.

BucketOperationsSample

Obtaining a Bucket List (SDK for Java)

obsClient.listBuckets(ListBucketsRequest request)

Lists all buckets that meet the specified conditions under the current account and returns them in alphabetical order.

BucketOperationsSample

Deleting a Bucket (SDK for Java)

obsClient.deleteBucket(String bucketName)

Deletes an empty bucket (the name of a deleted bucket can be reused at least 30 minutes after the deletion).

BucketOperationsSample

Checking Whether a Bucket Exists (SDK for Java)

obsClient.headBucket(String bucketName)

Checks whether a bucket exists (HTTP status code 200 indicates the bucket exists, while 404 indicates it does not).

BucketOperationsSample

Obtaining Bucket Metadata (SDK for Java)

obsClient.getBucketMetadata(BucketMetadataInfoRequest request)

Returns information about a bucket, including the storage class, region, CORS rules, and redundancy policy.

BucketOperationsSample

Configuring a Bucket ACL (SDK for Java)

obsClient.setBucketAcl(String bucketName,AccessControlList acl)

Sets an ACL for a bucket.

BucketOperationsSample

Obtaining a Bucket ACL (SDK for Java)

obsClient.getBucketAcl(String bucketName)

Returns the ACL of a bucket.

BucketOperationsSample

Configuring a Bucket Policy (SDK for Java)

obsClient.setBucketPolicy(String bucketName, String policy)

Sets a bucket policy.

BucketOperationsSample

Obtaining the Policy of a Bucket (SDK for Java)

obsClient.getBucketPolicy(String bucketName)

Returns a bucket policy.

BucketOperationsSample

Deleting a Bucket Policy (SDK for Java)

obsClient.deleteBucketPolicy(String bucketName)

Deletes a bucket policy (204 No Content is returned if the policy is deleted successfully or actually does not exist).

BucketOperationsSample

Obtaining the Region of a Bucket (SDK for Java)

obsClient.getBucketLocation(String bucketName)

Returns the region where the bucket is created.

BucketOperationsSample

Obtaining Storage Information of a Bucket (SDK for Java)

obsClient.getBucketStorageInfo(String bucketName)

Returns the storage information about a bucket, including the storage usage and the object count in the bucket.

BucketOperationsSample

Configuring a Storage Quota (SDK for Java)

obsClient.setBucketQuota(String bucketName, BucketQuota bucketQuota)

Sets a limit on the capacity of a bucket.

BucketOperationsSample

Obtaining a Bucket Storage Quota (SDK for Java)

obsClient.getBucketQuota(String bucketName)

Returns the quota of a bucket (0 indicates there is no upper limit to the capacity of the bucket).

BucketOperationsSample

Configuring a Storage Class for a Bucket (SDK for Java)

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).

BucketOperationsSample

Obtaining the Storage Class of a Bucket (SDK for Java)

obsClient.getBucketStoragePolicy(String bucketName)

Returns the storage class of a bucket.

BucketOperationsSample

Configuring an Inventory Rule (SDK for Java)

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).

BucketOperationsSample

Obtaining an Inventory Rule (SDK for Java)

obsClient.getInventoryConfiguration(GetInventoryConfigurationRequest request)

Returns a bucket inventory rule specified by the rule ID.

BucketOperationsSample

Listing Inventory Rules (SDK for Java)

obsClient.listInventoryConfiguration(ListInventoryConfigurationRequest request)

Returns all inventory rules of a bucket in a single response.

BucketOperationsSample

Deleting an Inventory Rule (SDK for Java)

obsClient.deleteInventoryConfiguration(DeleteInventoryConfigurationRequest request)

Deletes a bucket inventory rule specified by the rule ID.

BucketOperationsSample

Parallel File System APIs

Table 2 lists the APIs related to the parallel file system (PFS).

Table 2 PFS APIs

API

Method

Function

Creating a Parallel File System (SDK for Java)

obsClient.createBucket(CreateBucketRequest request)

Creates a PFS and configures the region and access permissions for the PFS.

Listing Parallel File Systems (SDK for Java)

obsClient.listBuckets(ListBucketsRequest request)

Lists all PFSs that meet the specified conditions under the current account and returns them in alphabetical order.

Listing Objects in a Parallel File System (SDK for Java)

obsClient.listObjects(final ListObjectsRequest request)

Lists the objects in a PFS.

Modifying an Object (SDK for Java)

obsClient.modifyObject(ModifyObjectRequest request)

Modifies the content of a file from a specific position.

Renaming an Object (SDK for Java)

obsClient.renameObject(RenameObjectRequest request)

Renames the file in a PFS.

Truncating an Object (SDK for Java)

obsClient.truncateObject(TruncateObjectRequest request)

Reduces the size of a file.

Object APIs

Table 3lists object-related APIs.

Table 3 Object APIs

API

Method

Function

Source Code Example

Uploading an Object - Streaming (SDK for Java)

obsClient.putObject(PutObjectRequest request)

Uploads local files of any type that are smaller than 5 GB to a bucket in streaming mode.

ObjectOperationsSample

Uploading an Object - File-Based (SDK for Java)

obsClient.putObject(PutObjectRequest request)

Uploads local files of any type to a bucket over the Internet.

-

Obtaining the Upload Progress (SDK for Java)

PutObjectRequest.setProgressListener(ProgressListener progressListener)

Returns the progress of uploading an object.

-

Creating a Folder (SDK for Java)

obsClient.putObject(PutObjectRequest request)

Creates a folder in a bucket to categorize the data.

CreateFolderSample

Configuring Object Metadata (SDK for Java)

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.

ObjectMetaSample

Initiating a Multipart Upload (SDK for Java)

obsClient.initiateMultipartUpload(InitiateMultipartUploadRequest request)

Initiates a multipart upload and returns a globally unique upload ID.

SimpleMultipartUploadSample

Uploading a Part (SDK for Java)

obsClient.uploadPart(UploadPartRequest request)

Uploads parts to the bucket based on the upload ID returned by the preceding API.

SimpleMultipartUploadSample

Assembling Parts (SDK for Java)

obsClient.completeMultipartUpload(CompleteMultipartUploadRequest request)

Completes a multipart upload based on the multipart upload ID and information about the uploaded parts (including PartNumber and ETag).

SimpleMultipartUploadSample

Aborting a Multipart Upload (SDK for Java)

obsClient.abortMultipartUpload(AbortMultipartUploadRequest request)

Aborts a multipart upload specified by the upload ID in a bucket.

-

Listing Uploaded Parts (SDK for Java)

obsClient.listParts(ListPartsRequest request)

Returns the uploaded parts in a bucket based on the specified multipart upload ID.

ConcurrentUploadPartSample

Listing Multipart Uploads (SDK for Java)

obsClient.listMultipartUploads(ListMultipartUploadsRequest request)

Lists ongoing multipart uploads.

-

Configuring Lifecycle Rules (SDK for Java)

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).

-

Uploading an Object - Append (SDK for Java)

obsClient.appendObject(AppendObjectRequest request)

Appends content to an existing object.

-

Uploading an Object - Resumable (SDK for Java)

obsClient.uploadFile(UploadFileRequest request)

Provides the resumable function based on the API for multipart uploads to better respond to network disconnections or program crashes.

-

Uploading an Object - Browser-Based (SDK for Java)

obsClient.createPostSignature(PostSignatureRequest request)

Uploads an object up to 5 GB in size to a bucket in the HTML form.

PostObjectSample

Downloading an Object - Streaming (SDK for Java)

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).

DownloadSample

Downloading an Object - Range-Based (SDK for Java)

obsClient.getObject(GetObjectRequest request)

Downloads the partial data of an object.

-

Obtaining the Download Progress (SDK for Java)

GetObjectRequest.setProgressListener(ProgressListener progressListener)

Returns the progress of downloading an object.

-

Downloading an Object - Conditional (SDK for Java)

obsClient.getObject(GetObjectRequest request)

Returns the objects that meet one or more specified conditions.

-

Rewriting Response Headers (SDK for Java)

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.

-

Obtaining User-defined Metadata (SDK for Java)

obsClient.getObject(GetObjectRequest request)

Returns the user-defined object metadata after the object is successfully downloaded.

ObjectMetaSample

Restoring an Archive Object (SDK for Java)

obsClient.restoreObject(RestoreObjectRequest request)

Restores and downloads an Archive object.

RestoreObjectSample

Downloading an Object - Resumable (SDK for Java)

obsClient.downloadFile(DownloadFileRequest request)

Adds the resumable function to the partial download API.

-

Downloading a Processed Image (SDK for Java)

obsClient.getObject(GetObjectRequest request)

Crops, re-sizes, or watermarks an image, or converts the image format before the download.

-

Creating a Signed URL for Downloading a Processed Image (SDK for Java)

obsClient.createTemporarySignature(TemporarySignatureRequest request)

Creates a signed URL for downloading a processed image.

-

Configuring Object Metadata (SDK for Java)

obsClient.setObjectMetadata(SetObjectMetadataRequest request)

Configures the object metadata.

-

Obtaining Object Metadata (SDK for Java)

obsClient.getObjectMetadata(GetObjectMetadataRequest request)

Returns the object metadata.

-

Configuring an Object ACL (SDK for Java)

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.

ObjectOperationsSample

Obtaining an Object ACL (SDK for Java)

obsClient.getObjectAcl(GetObjectAclRequest request)

Obtains the ACL of an object in a specified bucket.

ObjectOperationsSample

Listing Objects (SDK for Java)

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.

ListObjectsSample

Deleting an Object (SDK for Java)

obsClient.deleteObject(DeleteObjectRequest request)

Deletes an object from a bucket.

ObjectOperationsSample

Batch Deleting Objects (SDK for Java)

obsClient.deleteObjects(DeleteObjectsRequest deleteRequest)

Deletes objects from a bucket in a batch.

(Deleted objects cannot be restored.)

DeleteObjectsSample

Copying an Object (SDK for Java)

obsClient.copyObject(CopyObjectRequest request)

Creates a copy up to 5 GB for an object.

ObjectOperationsSample

Copying an Object - Multipart (SDK for Java)

obsClient.copyPart(CopyPartRequest request)

Copies parts to a specified bucket based on the multipart upload ID returned in initiating a multipart upload.

ConcurrentCopyPartSample

Checking Whether an Object Exists (SDK for Java)

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).

-

Temporarily Authorized Access APIs

Table 4 lists the APIs related to temporarily authorized access.

Table 4 Temporarily Authorized Access APIs

API

Method

Function

Source Code Example

Accessing OBS Using a Signed URL (SDK for Java)

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.)

TemporarySignatureSample

Versioning APIs

Table 5 lists the APIs related to versioning.

Table 5 Versioning APIs

API

Method

Function

Source Code Example

Configuring Versioning for a Bucket (SDK for Java)

obsClient.setBucketVersioning(final SetBucketVersioningRequest request)

Configures versioning for objects in a bucket.

BucketOperationsSample

Obtaining the Versioning Status of a Bucket (SDK for Java)

obsClient.getBucketVersioning(final BaseBucketRequest request)

Returns the versioning status of a bucket.

BucketOperationsSample

Obtaining an Object Version (SDK for Java)

obsClient.getObject(GetObjectRequest request)

Returns a specified object version.

-

Copying an Object Version (SDK for Java)

obsClient.copyObject(CopyObjectRequest request)

Creates a copy up to 5 GB for a versioned object.

-

Restoring a Specific Archive Object Version (SDK for Java)

obsClient.restoreObject(RestoreObjectRequest request)

Restores an Archive object version.

(To download an Archive object version, you need to restore it first.)

-

Listing Object Versions (SDK for Java)

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.

ListVersionsSample

Setting an ACL for an Object Version (SDK for Java)

obsClient.setObjectAcl(SetObjectAclRequest request)

Sets an ACL for an object version.

-

Obtaining the ACL of an Object Version (SDK for Java)

obsClient.getObjectAcl(GetObjectAclRequest request)

Returns the ACL of an object version.

-

Deleting an Object Version (SDK for Java)

obsClient.deleteObject(DeleteObjectRequest request)

Deletes the ACL of an object version.

-

Batch Deleting Object Versions (SDK for Java)

obsClient.deleteObjects(DeleteObjectsRequest deleteRequest)

Deletes object versions from a bucket in a batch.

(Deleted object versions cannot be restored.)

ListVersionsSample

Lifecycle Rule APIs

Table 6 lists the APIs related to lifecycle rules.

Table 6 Lifecycle Rule APIs

API

Method

Function

Source Code Example

Setting Lifecycle Rules (SDK for Java)

obsClient.setBucketLifecycle(final SetBucketLifecycleRequest request)

Sets a lifecycle rule for a bucket to periodically delete objects in the bucket or transition object storage classes.

BucketOperationsSample

Obtaining Lifecycle Rules (SDK for Java)

obsClient.getBucketLifecycle(final BaseBucketRequest request)

Returns a lifecycle rule of a bucket.

BucketOperationsSample

Deleting Lifecycle Rules (SDK for Java)

obsClient.deleteBucketLifecycle(final BaseBucketRequest request)

Deletes a lifecycle rule of a bucket.

BucketOperationsSample

CORS rule APIs

Table 7 lists the APIs related to CORS rules.

Table 7 CORS rule APIs

API

Method

Function

Source Code Example

Configuring a CORS Rule (SDK for Java)

obsclient.setBucketCors(final SetBucketCorsRequest request)

Sets a CORS rule for a bucket (the existing rules will be overwritten by the new ones).

BucketOperationsSample

Obtaining a CORS Rule (SDK for Java)

obsclient.getBucketCors(final BaseBucketRequest request)

Returns a CORS rule of a bucket.

BucketOperationsSample

Deleting a CORS Rule (SDK for Java)

obsclient.deleteBucketCors(final BaseBucketRequest request)

Deletes a CORS rule of a bucket.

BucketOperationsSample

Bucket Logging APIs

Table 8 lists the logging APIs.

Table 8 Bucket logging APIs

API

Method

Function

Source Code Example

Configuring Logging for a Bucket (SDK for Java)

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.

BucketOperationsSample

Obtaining the Logging Configuration of a Bucket (SDK for Java)

obsClient.getBucketLogging(final BaseBucketRequest request)

Returns the logging configuration of a bucket.

BucketOperationsSample

Static Website Hosting APIs

Table 9 lists the APIs related to static website hosting.

Table 9 Static website hosting APIs

API

Method

Function

Source Code Example

Hosting Website Files in a Bucket (SDK for Java)

  1. obsClient.putObject(PutObjectRequest request)
  2. obsClient.setObjectAcl(SetObjectAclRequest acl)

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.

-

Configuring Static Website Hosting (SDK for Java)

obsClient.setBucketWebsite(final SetBucketWebsiteRequest request)

Configures website hosting for a bucket.

BucketOperationsSample

Obtaining Static Website Hosting Configurations (SDK for Java)

obsClient.getBucketWebsite(final BaseBucketRequest request)

Returns the website configuration of a bucket.

BucketOperationsSample

Deleting Static Website Hosting Configurations (SDK for Java)

obsClient.deleteBucketWebsite(final BaseBucketRequest request)

Deletes the website configuration of a bucket.

BucketOperationsSample

Tagging APIs

Table 10 lists the APIs related to tagging.

Table 10 Tagging APIs

API

Method

Function

Source Code Example

Configuring Tags for a Bucket (SDK for Java)

obsClient.setBucketTagging(final SetBucketTaggingRequest request)

Tags a bucket to facilitate CDR filtering and cost analysis.

BucketOperationsSample

Obtaining Bucket Tags (SDK for Java)

obsClient.getBucketTagging(final BaseBucketRequest request)

Returns the tags of a bucket.

BucketOperationsSample

Deleting Bucket Tags (SDK for Java)

obsClient.deleteBucketTagging(final BaseBucketRequest request)

Deletes the tags of a bucket.

BucketOperationsSample