diff --git a/docs/obs_3rd_party/nodejs_sdk/ALL_META.TXT.json b/docs/obs_3rd_party/nodejs_sdk/ALL_META.TXT.json new file mode 100644 index 000000000..a186d2135 --- /dev/null +++ b/docs/obs_3rd_party/nodejs_sdk/ALL_META.TXT.json @@ -0,0 +1,2201 @@ +[ + { + "dockw":"Node.js SDK Developer Guide" + }, + { + "uri":"obs_29_0001.html", + "node_id":"obs_29_0001.xml", + "product_code":"obs", + "code":"1", + "des":"Latest version of OBS Node.js SDK: DownloadRecommended versions: Node 0.12.x, Node4.x, Node6.x, Node8.x, or Node10.xInterface changes: The following table describes the i", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an SDK,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an SDK", + "githuburl":"" + }, + { + "uri":"obs_29_0100.html", + "node_id":"obs_29_0100.xml", + "product_code":"obs", + "code":"2", + "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-nodejs-devg", + "kw":"Getting Started", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Getting Started", + "githuburl":"" + }, + { + "uri":"obs_29_0101.html", + "node_id":"obs_29_0101.xml", + "product_code":"obs", + "code":"3", + "des":"Ensure that you are familiar with OBS basic concepts from Help Center, such as bucket, object, region, and AK and SK.You can see General Ways to Use ObsClient to learn ho", + "doc_type":"sdk-nodejs-devg", + "kw":"Before You Start,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Before You Start", + "githuburl":"" + }, + { + "uri":"obs_29_0103.html", + "node_id":"obs_29_0103.xml", + "product_code":"obs", + "code":"4", + "des":"OBS uses access keys (AK and SK) for signature verification to ensure that only authorized accounts can access specified OBS resources. Detailed explanations are as follo", + "doc_type":"sdk-nodejs-devg", + "kw":"Creating Access Keys,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Creating Access Keys", + "githuburl":"" + }, + { + "uri":"obs_29_0104.html", + "node_id":"obs_29_0104.xml", + "product_code":"obs", + "code":"5", + "des":"Download the recommended version from the Node.js's official website and install it.Download the latest version of Eclipse IDE for JavaScript and Web Developer from Eclip", + "doc_type":"sdk-nodejs-devg", + "kw":"Preparing a Development Environment,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Preparing a Development Environment", + "githuburl":"" + }, + { + "uri":"obs_29_0105.html", + "node_id":"obs_29_0105.xml", + "product_code":"obs", + "code":"6", + "des":"The following procedures use OBS Node.js SDK of the latest version as an example.After the installation, the directory structure is similar to the following:├── examples├", + "doc_type":"sdk-nodejs-devg", + "kw":"Installing the SDK,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Installing the SDK", + "githuburl":"" + }, + { + "uri":"obs_29_0106.html", + "node_id":"obs_29_0106.xml", + "product_code":"obs", + "code":"7", + "des":"You can click here to view the endpoints and regions enabled for OBS.The SDK allows you to pass endpoints with or without the protocol name. Suppose the endpoint you obta", + "doc_type":"sdk-nodejs-devg", + "kw":"Obtaining Endpoints,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining Endpoints", + "githuburl":"" + }, + { + "uri":"obs_29_0107.html", + "node_id":"obs_29_0107.xml", + "product_code":"obs", + "code":"8", + "des":"Each time you want to send an HTTP/HTTPS request to OBS, you must create an instance ofObsClient. Sample code is as follows:JavaScript is an asynchronous programming lang", + "doc_type":"sdk-nodejs-devg", + "kw":"Initializing an Instance of ObsClient,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Initializing an Instance of ObsClient", + "githuburl":"" + }, + { + "uri":"obs_29_0108.html", + "node_id":"obs_29_0108.xml", + "product_code":"obs", + "code":"9", + "des":"A bucket is a global namespace of OBS and is a data container. It functions as a root directory of a file system and can store objects. The following code shows how to cr", + "doc_type":"sdk-nodejs-devg", + "kw":"Creating a Bucket,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Creating a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0109.html", + "node_id":"obs_29_0109.xml", + "product_code":"obs", + "code":"10", + "des":"This example uploads string Hello OBS to bucket examplebucket as object example/objectname.The example code is as follows:For more information, see Object Upload Overview", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading an Object,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object", + "githuburl":"" + }, + { + "uri":"obs_29_0110.html", + "node_id":"obs_29_0110.xml", + "product_code":"obs", + "code":"11", + "des":"This example downloads object example/objectname from bucket examplebucket.The example code is as follows:For more information, see Overview.", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object", + "githuburl":"" + }, + { + "uri":"obs_29_0111.html", + "node_id":"obs_29_0111.xml", + "product_code":"obs", + "code":"12", + "des":"After objects are uploaded, you may want to view the objects contained in a bucket. Sample code is as follows:// Import the OBS library.\n// Use npm to install the client.", + "doc_type":"sdk-nodejs-devg", + "kw":"Listing Objects,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Listing Objects", + "githuburl":"" + }, + { + "uri":"obs_29_0112.html", + "node_id":"obs_29_0112.xml", + "product_code":"obs", + "code":"13", + "des":"This example deletes object example/objectname from bucket examplebucket.The example code is as follows:For more information, see Deleting an Object.", + "doc_type":"sdk-nodejs-devg", + "kw":"Deleting an Object,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting an Object", + "githuburl":"" + }, + { + "uri":"obs_29_0113.html", + "node_id":"obs_29_0113.xml", + "product_code":"obs", + "code":"14", + "des":"ObsClient returns the results by using a callback function that contains two parameters in sequence: the exception information parameter and the SDK common result object ", + "doc_type":"sdk-nodejs-devg", + "kw":"General Ways to Use ObsClient,Getting Started,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"General Ways to Use ObsClient", + "githuburl":"" + }, + { + "uri":"obs_29_0200.html", + "node_id":"obs_29_0200.xml", + "product_code":"obs", + "code":"15", + "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-nodejs-devg", + "kw":"Initialization", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Initialization", + "githuburl":"" + }, + { + "uri":"obs_29_0201.html", + "node_id":"obs_29_0201.xml", + "product_code":"obs", + "code":"16", + "des":"To use OBS, you need a valid pair of AK and SK for signature authentication.After obtaining the AK and SK, you can create an instance of ObsClient to call SDK APIs.For de", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring Access Keys,Initialization,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Access Keys", + "githuburl":"" + }, + { + "uri":"obs_29_0202.html", + "node_id":"obs_29_0202.xml", + "product_code":"obs", + "code":"17", + "des":"ObsClient functions as the Node.js client for accessing OBS. It offers callers a series of APIs for interaction with OBS and is used for managing and operating resources,", + "doc_type":"sdk-nodejs-devg", + "kw":"Creating an Instance of ObsClient,Initialization,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Creating an Instance of ObsClient", + "githuburl":"" + }, + { + "uri":"obs_29_0203.html", + "node_id":"obs_29_0203.xml", + "product_code":"obs", + "code":"18", + "des":"You can set the following initialization parameters to configure an instance of ObsClient.Parameters whose recommended value is N/A need to be set according to the actual", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring an Instance of ObsClient,Initialization,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring an Instance of ObsClient", + "githuburl":"" + }, + { + "uri":"obs_29_0204.html", + "node_id":"obs_29_0204.xml", + "product_code":"obs", + "code":"19", + "des":"OBS Node.js SDK provides the logging function based on Log4js. You can call ObsClient.initLog to enable and configure logging. The following is a code sample:The logging ", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring SDK Logging,Initialization,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring SDK Logging", + "githuburl":"" + }, + { + "uri":"obs_29_0300.html", + "node_id":"obs_29_0300.xml", + "product_code":"obs", + "code":"20", + "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-nodejs-devg", + "kw":"Bucket Management", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Bucket Management", + "githuburl":"" + }, + { + "uri":"obs_29_0301.html", + "node_id":"obs_29_0301.xml", + "product_code":"obs", + "code":"21", + "des":"OBS buckets are containers for storing objects you upload to OBS. This API creates a bucket.When creating a bucket, you can also configure parameters such as the storage ", + "doc_type":"sdk-nodejs-devg", + "kw":"Creating a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Creating a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0302.html", + "node_id":"obs_29_0302.xml", + "product_code":"obs", + "code":"22", + "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-nodejs-devg", + "kw":"Listing Buckets,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Listing Buckets", + "githuburl":"" + }, + { + "uri":"obs_29_0304.html", + "node_id":"obs_29_0304.xml", + "product_code":"obs", + "code":"23", + "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-nodejs-devg", + "kw":"Checking Whether a Bucket Exists,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Checking Whether a Bucket Exists", + "githuburl":"" + }, + { + "uri":"obs_29_0303.html", + "node_id":"obs_29_0303.xml", + "product_code":"obs", + "code":"24", + "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-nodejs-devg", + "kw":"Deleting a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0305.html", + "node_id":"obs_29_0305.xml", + "product_code":"obs", + "code":"25", + "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-nodejs-devg", + "kw":"Obtaining Bucket Metadata,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining Bucket Metadata", + "githuburl":"" + }, + { + "uri":"obs_29_0306.html", + "node_id":"obs_29_0306.xml", + "product_code":"obs", + "code":"26", + "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-nodejs-devg", + "kw":"Configuring a Bucket ACL,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring a Bucket ACL", + "githuburl":"" + }, + { + "uri":"obs_29_0307.html", + "node_id":"obs_29_0307.xml", + "product_code":"obs", + "code":"27", + "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-nodejs-devg", + "kw":"Obtaining a Bucket ACL,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining a Bucket ACL", + "githuburl":"" + }, + { + "uri":"obs_29_0308.html", + "node_id":"obs_29_0308.xml", + "product_code":"obs", + "code":"28", + "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-nodejs-devg", + "kw":"Configuring a Bucket Policy,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring a Bucket Policy", + "githuburl":"" + }, + { + "uri":"obs_29_0309.html", + "node_id":"obs_29_0309.xml", + "product_code":"obs", + "code":"29", + "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-nodejs-devg", + "kw":"Obtaining the Policy of a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the Policy of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0310.html", + "node_id":"obs_29_0310.xml", + "product_code":"obs", + "code":"30", + "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-nodejs-devg", + "kw":"Deleting a Bucket Policy,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting a Bucket Policy", + "githuburl":"" + }, + { + "uri":"obs_29_0311.html", + "node_id":"obs_29_0311.xml", + "product_code":"obs", + "code":"31", + "des":"This API returns the region of a bucket.To obtain the region of a bucket, you must be the bucket owner or have the required permission (obs:bucket:GetBucketLocation in IA", + "doc_type":"sdk-nodejs-devg", + "kw":"Obtaining the Region of a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the Region of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0312.html", + "node_id":"obs_29_0312.xml", + "product_code":"obs", + "code":"32", + "des":"This API returns the storage information on 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-nodejs-devg", + "kw":"Obtaining Storage Information of a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining Storage Information of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0313.html", + "node_id":"obs_29_0313.xml", + "product_code":"obs", + "code":"33", + "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-nodejs-devg", + "kw":"Configuring a Storage Quota for a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring a Storage Quota for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0314.html", + "node_id":"obs_29_0314.xml", + "product_code":"obs", + "code":"34", + "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 storage q", + "doc_type":"sdk-nodejs-devg", + "kw":"Obtaining the Storage Quota of a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the Storage Quota of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0315.html", + "node_id":"obs_29_0315.xml", + "product_code":"obs", + "code":"35", + "des":"This API configures a storage class for a bucket. If you upload or copy objects to a bucket with a storage class configured or initiating a multipart upload for such a bu", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring a Storage Class for a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring a Storage Class for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0316.html", + "node_id":"obs_29_0316.xml", + "product_code":"obs", + "code":"36", + "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-nodejs-devg", + "kw":"Obtaining the Storage Class of a Bucket,Bucket Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the Storage Class of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0400.html", + "node_id":"obs_29_0400.xml", + "product_code":"obs", + "code":"37", + "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-nodejs-devg", + "kw":"Object Upload", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Object Upload", + "githuburl":"" + }, + { + "uri":"obs_29_0401.html", + "node_id":"obs_29_0401.xml", + "product_code":"obs", + "code":"38", + "des":"In OBS, objects are basic data units that users can perform operations on. OBS Node.js SDK provides abundant APIs for object upload in the following methods:Uploading an ", + "doc_type":"sdk-nodejs-devg", + "kw":"Object Upload Overview,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Object Upload Overview", + "githuburl":"" + }, + { + "uri":"obs_29_0402.html", + "node_id":"obs_29_0402.xml", + "product_code":"obs", + "code":"39", + "des":"This API uploads an object to a bucket.To upload an object, you must be the bucket owner or have the required permission (obs:object:PutObject in IAM or PutObject in a bu", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading an Object - Text-Based,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object - Text-Based", + "githuburl":"" + }, + { + "uri":"obs_29_0403.html", + "node_id":"obs_29_0403.xml", + "product_code":"obs", + "code":"40", + "des":"This API uploads an object to a bucket.To upload an object, you must be the bucket owner or have the required permission (obs:object:PutObject in IAM or PutObject in a bu", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading an Object - Streaming,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object - Streaming", + "githuburl":"" + }, + { + "uri":"obs_29_0404.html", + "node_id":"obs_29_0404.xml", + "product_code":"obs", + "code":"41", + "des":"This API uploads an object to a bucket.To upload an object, you must be the bucket owner or have the required permission (obs:object:PutObject in IAM or PutObject in a bu", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading an Object - File-Based,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object - File-Based", + "githuburl":"" + }, + { + "uri":"obs_29_0405.html", + "node_id":"obs_29_0405.xml", + "product_code":"obs", + "code":"42", + "des":"This API uploads a folder object to a bucket to make it easy to manage data stored in the bucket.To upload an object, you must be the bucket owner or have the required pe", + "doc_type":"sdk-nodejs-devg", + "kw":"Creating a Folder,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Creating a Folder", + "githuburl":"" + }, + { + "uri":"obs_29_0406.html", + "node_id":"obs_29_0406.xml", + "product_code":"obs", + "code":"43", + "des":"Object metadata contains a set of name-value pairs that are used for describing and managing objects.Currently, only the system-defined metadata is supported. System-defi", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring Object Metadata,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Object Metadata", + "githuburl":"" + }, + { + "uri":"obs_29_0407.html", + "node_id":"obs_29_0407.xml", + "product_code":"obs", + "code":"44", + "des":"When uploading an object or initiating a multipart upload, you can set an expiration time for the object using Expires. This method only supports setting the object expir", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring a Lifecycle Rule When Uploading an Object,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring a Lifecycle Rule When Uploading an Object", + "githuburl":"" + }, + { + "uri":"obs_29_0409.html", + "node_id":"obs_29_0409.xml", + "product_code":"obs", + "code":"45", + "des":"This API uploads a file or folder to an existing OBS bucket. You can upload text, pictures, videos, or any other types of files.This API adds data to the end of a specifi", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading an Object - Append,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object - Append", + "githuburl":"" + }, + { + "uri":"obs_29_0411.html", + "node_id":"obs_29_0411.xml", + "product_code":"obs", + "code":"46", + "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-nodejs-devg", + "kw":"Uploading an Object - Resumable,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object - Resumable", + "githuburl":"" + }, + { + "uri":"obs_29_0412.html", + "node_id":"obs_29_0412.xml", + "product_code":"obs", + "code":"47", + "des":"Performing a browser-based upload is to upload objects to a specified bucket in HTML form. The maximum size of an object is 5 GB.You can call ObsClient.createPostSignatur", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading an Object - Browser-Based,Object Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading an Object - Browser-Based", + "githuburl":"" + }, + { + "uri":"obs_29_0500.html", + "node_id":"obs_29_0500.xml", + "product_code":"obs", + "code":"48", + "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-nodejs-devg", + "kw":"Object Download", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Object Download", + "githuburl":"" + }, + { + "uri":"obs_29_0501.html", + "node_id":"obs_29_0501.xml", + "product_code":"obs", + "code":"49", + "des":"OBS Node.js SDK provides abundant APIs for downloading objects in the following modes:Downloading an Object - Text-BasedDownloading an Object - StreamingDownloading an Ob", + "doc_type":"sdk-nodejs-devg", + "kw":"Overview,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_29_0502.html", + "node_id":"obs_29_0502.xml", + "product_code":"obs", + "code":"50", + "des":"This API downloads an object as text from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:GetOb", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object - Text-Based,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object - Text-Based", + "githuburl":"" + }, + { + "uri":"obs_29_0503.html", + "node_id":"obs_29_0503.xml", + "product_code":"obs", + "code":"51", + "des":"This API downloads an object as a stream from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:G", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object - Streaming,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object - Streaming", + "githuburl":"" + }, + { + "uri":"obs_29_0504.html", + "node_id":"obs_29_0504.xml", + "product_code":"obs", + "code":"52", + "des":"This API downloads an object as a file from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:Get", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object - File-Based,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object - File-Based", + "githuburl":"" + }, + { + "uri":"obs_29_0505.html", + "node_id":"obs_29_0505.xml", + "product_code":"obs", + "code":"53", + "des":"This API downloads part of an object from OBS to your local computer. If the specified range is from 0 to 1,000, data from byte 0 to byte 1,000, 1,001 bytes in total, are", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object - Range-Based,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object - Range-Based", + "githuburl":"" + }, + { + "uri":"obs_29_0506.html", + "node_id":"obs_29_0506.xml", + "product_code":"obs", + "code":"54", + "des":"This API downloads objects that meet specified conditions from OBS to a local computer.To download an object, you must be the bucket owner or have the required permission", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object - Conditional,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object - Conditional", + "githuburl":"" + }, + { + "uri":"obs_29_0507.html", + "node_id":"obs_29_0507.xml", + "product_code":"obs", + "code":"55", + "des":"When downloading an object, you can rewrite some HTTP/HTTPS response headers. The following table lists rewritable response headers.This code example rewrites response he", + "doc_type":"sdk-nodejs-devg", + "kw":"Rewriting Response Headers,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Rewriting Response Headers", + "githuburl":"" + }, + { + "uri":"obs_29_0509.html", + "node_id":"obs_29_0509.xml", + "product_code":"obs", + "code":"56", + "des":"To prolong the validity period of the Cold data restored, you can repeatedly restore the data, but you will be billed for each restoration. After a second restore, the va", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading a Cold Object,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading a Cold Object", + "githuburl":"" + }, + { + "uri":"obs_29_0510.html", + "node_id":"obs_29_0510.xml", + "product_code":"obs", + "code":"57", + "des":"The API for resumable download is an encapsulated and enhanced version of range-based download. Downloading large files often fails due to an unstable network or program ", + "doc_type":"sdk-nodejs-devg", + "kw":"Downloading an Object - Resumable,Object Download,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Downloading an Object - Resumable", + "githuburl":"" + }, + { + "uri":"obs_29_0600.html", + "node_id":"obs_29_0600.xml", + "product_code":"obs", + "code":"58", + "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-nodejs-devg", + "kw":"Object Management", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Object Management", + "githuburl":"" + }, + { + "uri":"obs_29_0602.html", + "node_id":"obs_29_0602.xml", + "product_code":"obs", + "code":"59", + "des":"Object metadata contains a set of name-value pairs that are used for describing and managing objects.Currently, system-defined and custom metadata are supported.System-de", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring Object Metadata,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Object Metadata", + "githuburl":"" + }, + { + "uri":"obs_29_0601.html", + "node_id":"obs_29_0601.xml", + "product_code":"obs", + "code":"60", + "des":"Object metadata contains a set of name-value pairs that are used for describing and managing objects.Currently, only the system-defined metadata is supported. System-defi", + "doc_type":"sdk-nodejs-devg", + "kw":"Obtaining Object Metadata,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining Object Metadata", + "githuburl":"" + }, + { + "uri":"obs_29_0604.html", + "node_id":"obs_29_0604.xml", + "product_code":"obs", + "code":"61", + "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-nodejs-devg", + "kw":"Configuring an Object ACL,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring an Object ACL", + "githuburl":"" + }, + { + "uri":"obs_29_0603.html", + "node_id":"obs_29_0603.xml", + "product_code":"obs", + "code":"62", + "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-nodejs-devg", + "kw":"Obtaining the ACL of an Object,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the ACL of an Object", + "githuburl":"" + }, + { + "uri":"obs_29_0605.html", + "node_id":"obs_29_0605.xml", + "product_code":"obs", + "code":"63", + "des":"This API lists some or all of the objects in a bucket. You can configure the prefix, number, or start position as the filter to list objects. Returned objects are listed ", + "doc_type":"sdk-nodejs-devg", + "kw":"Listing Objects in a Bucket,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Listing Objects in a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0606.html", + "node_id":"obs_29_0606.xml", + "product_code":"obs", + "code":"64", + "des":"Exercise caution when performing this operation. If the versioning function is disabled for the bucket where the object is located, the object cannot be restored after be", + "doc_type":"sdk-nodejs-devg", + "kw":"Deleting an Object,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting an Object", + "githuburl":"" + }, + { + "uri":"obs_29_0607.html", + "node_id":"obs_29_0607.xml", + "product_code":"obs", + "code":"65", + "des":"Exercise caution when performing this operation. If versioning is disabled for the bucket where objects are located, objects cannot be restored after being deleted.This A", + "doc_type":"sdk-nodejs-devg", + "kw":"Batch Deleting Objects,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Batch Deleting Objects", + "githuburl":"" + }, + { + "uri":"obs_29_0608.html", + "node_id":"obs_29_0608.xml", + "product_code":"obs", + "code":"66", + "des":"This API copies an object stored in OBS to a specified path. You can copy an object of up to 5 GB in a single operation.To copy an object, you must be the bucket owner or", + "doc_type":"sdk-nodejs-devg", + "kw":"Copying an Object,Object Management,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Copying an Object", + "githuburl":"" + }, + { + "uri":"obs_29_1900.html", + "node_id":"obs_29_1900.xml", + "product_code":"obs", + "code":"67", + "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-nodejs-devg", + "kw":"Multipart Upload", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_29_1901.html", + "node_id":"obs_29_1901.xml", + "product_code":"obs", + "code":"68", + "des":"To upload a large file, multipart upload is recommended. Multipart upload is applicable to many scenarios. Below are some examples.Files to be uploaded are larger than 10", + "doc_type":"sdk-nodejs-devg", + "kw":"Multipart Upload APIs,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Multipart Upload APIs", + "githuburl":"" + }, + { + "uri":"obs_29_1902.html", + "node_id":"obs_29_1902.xml", + "product_code":"obs", + "code":"69", + "des":"This API initiates a multipart upload and returns a globally unique upload ID. You can use this upload ID in your subsequent requests for uploading, assembling, and listi", + "doc_type":"sdk-nodejs-devg", + "kw":"Initiating a Multipart Upload,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Initiating a Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_29_1903.html", + "node_id":"obs_29_1903.xml", + "product_code":"obs", + "code":"70", + "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.When uploading a par", + "doc_type":"sdk-nodejs-devg", + "kw":"Uploading a Part,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Uploading a Part", + "githuburl":"" + }, + { + "uri":"obs_29_1904.html", + "node_id":"obs_29_1904.xml", + "product_code":"obs", + "code":"71", + "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-nodejs-devg", + "kw":"Assembling Parts,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Assembling Parts", + "githuburl":"" + }, + { + "uri":"obs_29_1905.html", + "node_id":"obs_29_1905.xml", + "product_code":"obs", + "code":"72", + "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-nodejs-devg", + "kw":"Listing Uploaded Parts,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Listing Uploaded Parts", + "githuburl":"" + }, + { + "uri":"obs_29_1906.html", + "node_id":"obs_29_1906.xml", + "product_code":"obs", + "code":"73", + "des":"This API lists multipart uploads that have been initiated but not completed or cancelled.You can list all the multipart uploads that are not assembled or aborted in a buc", + "doc_type":"sdk-nodejs-devg", + "kw":"Listing Multipart Uploads,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Listing Multipart Uploads", + "githuburl":"" + }, + { + "uri":"obs_29_1907.html", + "node_id":"obs_29_1907.xml", + "product_code":"obs", + "code":"74", + "des":"This API uploads a part for a specified multipart upload by copying data to a specified bucket.After initiating a multipart upload task, you can add parts for this task b", + "doc_type":"sdk-nodejs-devg", + "kw":"Copying a Part,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Copying a Part", + "githuburl":"" + }, + { + "uri":"obs_29_1908.html", + "node_id":"obs_29_1908.xml", + "product_code":"obs", + "code":"75", + "des":"This API aborts a multipart upload by specifying its ID.After a multipart upload is aborted, its upload ID cannot be used to upload any part. And the space occupied by al", + "doc_type":"sdk-nodejs-devg", + "kw":"Aborting a Multipart Upload,Multipart Upload,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Aborting a Multipart Upload", + "githuburl":"" + }, + { + "uri":"obs_29_0700.html", + "node_id":"obs_29_0700.xml", + "product_code":"obs", + "code":"76", + "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-nodejs-devg", + "kw":"Temporarily Authorized Access", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Temporarily Authorized Access", + "githuburl":"" + }, + { + "uri":"obs_29_0701.html", + "node_id":"obs_29_0701.xml", + "product_code":"obs", + "code":"77", + "des":"OBS allows you to create a URL whose Query parameters carry authentication information by specifying the AK and SK, HTTP method, and request parameters. You can provide t", + "doc_type":"sdk-nodejs-devg", + "kw":"Using a Temporary URL for Authorized Access,Temporarily Authorized Access,Node.js SDK Developer Guid", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Using a Temporary URL for Authorized Access", + "githuburl":"" + }, + { + "uri":"obs_29_0800.html", + "node_id":"obs_29_0800.xml", + "product_code":"obs", + "code":"78", + "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-nodejs-devg", + "kw":"Versioning", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Versioning", + "githuburl":"" + }, + { + "uri":"obs_29_0801.html", + "node_id":"obs_29_0801.xml", + "product_code":"obs", + "code":"79", + "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-nodejs-devg", + "kw":"Versioning Overview,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Versioning Overview", + "githuburl":"" + }, + { + "uri":"obs_29_0802.html", + "node_id":"obs_29_0802.xml", + "product_code":"obs", + "code":"80", + "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-nodejs-devg", + "kw":"Configuring Versioning for a Bucket,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Versioning for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0803.html", + "node_id":"obs_29_0803.xml", + "product_code":"obs", + "code":"81", + "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-nodejs-devg", + "kw":"Viewing the Versioning Status of a Bucket,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Viewing the Versioning Status of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0804.html", + "node_id":"obs_29_0804.xml", + "product_code":"obs", + "code":"82", + "des":"This API downloads an object version from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:GetOb", + "doc_type":"sdk-nodejs-devg", + "kw":"Obtaining an Object Version,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining an Object Version", + "githuburl":"" + }, + { + "uri":"obs_29_0805.html", + "node_id":"obs_29_0805.xml", + "product_code":"obs", + "code":"83", + "des":"This API copies an object version in a specified bucket. You can copy an object of up to 5 GB in a single operation.To copy an object, you must be the bucket owner or hav", + "doc_type":"sdk-nodejs-devg", + "kw":"Copying an Object Version,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Copying an Object Version", + "githuburl":"" + }, + { + "uri":"obs_29_0806.html", + "node_id":"obs_29_0806.xml", + "product_code":"obs", + "code":"84", + "des":"To download an object in the Cold storage class, you need to restore it first. After an object is restored, a copy of the object is saved in the Standard storage class. B", + "doc_type":"sdk-nodejs-devg", + "kw":"Restoring a Cold Object Version,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Restoring a Cold Object Version", + "githuburl":"" + }, + { + "uri":"obs_29_0807.html", + "node_id":"obs_29_0807.xml", + "product_code":"obs", + "code":"85", + "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-nodejs-devg", + "kw":"Listing Object Versions in a Bucket,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Listing Object Versions in a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0808.html", + "node_id":"obs_29_0808.xml", + "product_code":"obs", + "code":"86", + "des":"This API calls ObsClient.setObjectAcl to set an ACL for an object version specified by the VersionId parameter. For details about the API definition, see Configuring an O", + "doc_type":"sdk-nodejs-devg", + "kw":"Setting an ACL for an Object Version,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Setting an ACL for an Object Version", + "githuburl":"" + }, + { + "uri":"obs_29_1308.html", + "node_id":"obs_29_1308.xml", + "product_code":"obs", + "code":"87", + "des":"This API calls ObsClient.getObjectAcl to obtain the ACL of an object version specified by the VersionId parameter. For details about the API definition, see Obtaining the", + "doc_type":"sdk-nodejs-devg", + "kw":"Obtaining the ACL of an Object Version,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the ACL of an Object Version", + "githuburl":"" + }, + { + "uri":"obs_29_0809.html", + "node_id":"obs_29_0809.xml", + "product_code":"obs", + "code":"88", + "des":"You can call ObsClient.deleteObject to delete an object version specified by the VersionId parameter. For details about the API definition, see Deleting an Object.You can", + "doc_type":"sdk-nodejs-devg", + "kw":"Deleting an Object Version,Versioning,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting an Object Version", + "githuburl":"" + }, + { + "uri":"obs_29_0900.html", + "node_id":"obs_29_0900.xml", + "product_code":"obs", + "code":"89", + "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-nodejs-devg", + "kw":"Lifecycle", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Lifecycle", + "githuburl":"" + }, + { + "uri":"obs_29_0902.html", + "node_id":"obs_29_0902.xml", + "product_code":"obs", + "code":"90", + "des":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API configures lifecycle rules for a bucket.Expired ob", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring Lifecycle Rules for a Bucket,Lifecycle,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Lifecycle Rules for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0903.html", + "node_id":"obs_29_0903.xml", + "product_code":"obs", + "code":"91", + "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-nodejs-devg", + "kw":"Obtaining the Lifecycle Rules of a Bucket,Lifecycle,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the Lifecycle Rules of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_0904.html", + "node_id":"obs_29_0904.xml", + "product_code":"obs", + "code":"92", + "des":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API deletes the lifecycle rules of a bucket.To delete ", + "doc_type":"sdk-nodejs-devg", + "kw":"Deleting the Lifecycle Rules of a Bucket,Lifecycle,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting the Lifecycle Rules of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_1000.html", + "node_id":"obs_29_1000.xml", + "product_code":"obs", + "code":"93", + "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-nodejs-devg", + "kw":"Bucket CORS", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Bucket CORS", + "githuburl":"" + }, + { + "uri":"obs_29_1002.html", + "node_id":"obs_29_1002.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-nodejs-devg", + "kw":"Configuring CORS for a Bucket,Bucket CORS,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring CORS for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_1003.html", + "node_id":"obs_29_1003.xml", + "product_code":"obs", + "code":"95", + "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-nodejs-devg", + "kw":"Obtaining the CORS Configuration of a Bucket,Bucket CORS,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the CORS Configuration of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_1004.html", + "node_id":"obs_29_1004.xml", + "product_code":"obs", + "code":"96", + "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-nodejs-devg", + "kw":"Deleting the CORS Configuration of a Bucket,Bucket CORS,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting the CORS Configuration of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_1100.html", + "node_id":"obs_29_1100.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-nodejs-devg", + "kw":"Logging", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Logging", + "githuburl":"" + }, + { + "uri":"obs_29_1102.html", + "node_id":"obs_29_1102.xml", + "product_code":"obs", + "code":"98", + "des":"A bucket in the Warm or Cold storage class cannot be used as a log target bucket.This API enables logging for a bucket (source) and configures another bucket (target) to ", + "doc_type":"sdk-nodejs-devg", + "kw":"Configuring Logging for a Bucket,Logging,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Logging for a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_1103.html", + "node_id":"obs_29_1103.xml", + "product_code":"obs", + "code":"99", + "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-nodejs-devg", + "kw":"Obtaining the Logging Configuration of a Bucket,Logging,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining the Logging Configuration of a Bucket", + "githuburl":"" + }, + { + "uri":"obs_29_1200.html", + "node_id":"obs_29_1200.xml", + "product_code":"obs", + "code":"100", + "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-nodejs-devg", + "kw":"Static Website Hosting", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Static Website Hosting", + "githuburl":"" + }, + { + "uri":"obs_29_1201.html", + "node_id":"obs_29_1201.xml", + "product_code":"obs", + "code":"101", + "des":"You can upload the content files of the static website to your bucket in OBS as objects and configure the public-read permission on the files, and then configure the stat", + "doc_type":"sdk-nodejs-devg", + "kw":"Overview,Static Website Hosting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Overview", + "githuburl":"" + }, + { + "uri":"obs_29_1203.html", + "node_id":"obs_29_1203.xml", + "product_code":"obs", + "code":"102", + "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-nodejs-devg", + "kw":"Configuring Static Website Hosting,Static Website Hosting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Configuring Static Website Hosting", + "githuburl":"" + }, + { + "uri":"obs_29_1204.html", + "node_id":"obs_29_1204.xml", + "product_code":"obs", + "code":"103", + "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-nodejs-devg", + "kw":"Obtaining Static Website Hosting Configurations,Static Website Hosting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining Static Website Hosting Configurations", + "githuburl":"" + }, + { + "uri":"obs_29_1205.html", + "node_id":"obs_29_1205.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-nodejs-devg", + "kw":"Deleting Website Hosting Settings,Static Website Hosting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting Website Hosting Settings", + "githuburl":"" + }, + { + "uri":"obs_29_1300.html", + "node_id":"obs_29_1300.xml", + "product_code":"obs", + "code":"105", + "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-nodejs-devg", + "kw":"Tagging", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Tagging", + "githuburl":"" + }, + { + "uri":"obs_29_1302.html", + "node_id":"obs_29_1302.xml", + "product_code":"obs", + "code":"106", + "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-nodejs-devg", + "kw":"Setting Bucket Tags,Tagging,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Setting Bucket Tags", + "githuburl":"" + }, + { + "uri":"obs_29_1303.html", + "node_id":"obs_29_1303.xml", + "product_code":"obs", + "code":"107", + "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-nodejs-devg", + "kw":"Obtaining Bucket Tags,Tagging,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Obtaining Bucket Tags", + "githuburl":"" + }, + { + "uri":"obs_29_1304.html", + "node_id":"obs_29_1304.xml", + "product_code":"obs", + "code":"108", + "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-nodejs-devg", + "kw":"Deleting Bucket Tags,Tagging,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Deleting Bucket Tags", + "githuburl":"" + }, + { + "uri":"obs_29_1500.html", + "node_id":"obs_29_1500.xml", + "product_code":"obs", + "code":"109", + "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-nodejs-devg", + "kw":"Server-Side Encryption", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Server-Side Encryption", + "githuburl":"" + }, + { + "uri":"obs_29_1502.html", + "node_id":"obs_29_1502.xml", + "product_code":"obs", + "code":"110", + "des":"The following table lists APIs related to server-side encryption:OBS Node.js SDK supports the following two types of encryption/decryption mode:", + "doc_type":"sdk-nodejs-devg", + "kw":"APIs,Server-Side Encryption,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"APIs", + "githuburl":"" + }, + { + "uri":"obs_29_1503.html", + "node_id":"obs_29_1503.xml", + "product_code":"obs", + "code":"111", + "des":"This example uploads object example/objectname to bucket examplebucket and encrypts it using SSE-C.This example downloads the encrypted object example/objectname using a ", + "doc_type":"sdk-nodejs-devg", + "kw":"Code Examples,Server-Side Encryption,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Code Examples", + "githuburl":"" + }, + { + "uri":"obs_29_1600.html", + "node_id":"obs_29_1600.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-nodejs-devg", + "kw":"Troubleshooting", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Troubleshooting", + "githuburl":"" + }, + { + "uri":"obs_29_1601.html", + "node_id":"obs_29_1601.xml", + "product_code":"obs", + "code":"113", + "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-nodejs-devg", + "kw":"OBS Server-Side Error Codes,Troubleshooting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"OBS Server-Side Error Codes", + "githuburl":"" + }, + { + "uri":"obs_29_1602.html", + "node_id":"obs_29_1602.xml", + "product_code":"obs", + "code":"114", + "des":"After you call an API in an instance of the ObsClient class, a common result object will be returned if no exception is thrown. The following table lists the fields of th", + "doc_type":"sdk-nodejs-devg", + "kw":"SDK Common Results,Troubleshooting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"SDK Common Results", + "githuburl":"" + }, + { + "uri":"obs_29_1603.html", + "node_id":"obs_29_1603.xml", + "product_code":"obs", + "code":"115", + "des":"OBS Node.js SDK provides the logging function based on Log4js. You can call ObsClient.initLogto enable and configure logging. The sample code is as follows:The logging fu", + "doc_type":"sdk-nodejs-devg", + "kw":"Log Analysis,Troubleshooting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Log Analysis", + "githuburl":"" + }, + { + "uri":"obs_29_1604.html", + "node_id":"obs_29_1604.xml", + "product_code":"obs", + "code":"116", + "des":"Problem: When OBS Node.js SDK is used for secondary development, an error message was displayed indicating that a module was missing, for example, \"Cannot find module 'xm", + "doc_type":"sdk-nodejs-devg", + "kw":"Missing Modules,Troubleshooting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Missing Modules", + "githuburl":"" + }, + { + "uri":"obs_29_1605.html", + "node_id":"obs_29_1605.xml", + "product_code":"obs", + "code":"117", + "des":"Problem: If a \"connect ETIMEDOUT\" error occurred when calling an API, the possible cause was that the service address (endpoint) was incorrect or the network was disconne", + "doc_type":"sdk-nodejs-devg", + "kw":"Connection Timeout,Troubleshooting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Connection Timeout", + "githuburl":"" + }, + { + "uri":"obs_29_1606.html", + "node_id":"obs_29_1606.xml", + "product_code":"obs", + "code":"118", + "des":"Problem: The HTTP status code obtained from CommonMsg.Status was 403, and the OBS server-side error code obtained from CommonMsg.Code was SignatureDoesNotMatch.Solution:C", + "doc_type":"sdk-nodejs-devg", + "kw":"Unmatched Signatures,Troubleshooting,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Unmatched Signatures", + "githuburl":"" + }, + { + "uri":"obs_29_1700.html", + "node_id":"obs_29_1700.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-nodejs-devg", + "kw":"FAQs", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"FAQs", + "githuburl":"" + }, + { + "uri":"obs_29_1715.html", + "node_id":"obs_29_1715.xml", + "product_code":"obs", + "code":"120", + "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-nodejs-devg", + "kw":"How Do I Get My Account ID and User ID?,FAQs,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"How Do I Get My Account ID and User ID?", + "githuburl":"" + }, + { + "uri":"obs_29_1716.html", + "node_id":"obs_29_1716.xml", + "product_code":"obs", + "code":"121", + "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-nodejs-devg", + "kw":"What Is Content-Type (MIME)?,FAQs,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"What Is Content-Type (MIME)?", + "githuburl":"" + }, + { + "uri":"obs_29_1802.html", + "node_id":"obs_29_1802.xml", + "product_code":"obs", + "code":"122", + "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-nodejs-devg", + "kw":"Change History,Node.js SDK Developer Guide", + "search_title":"", + "metedata":[ + { + "prodname":"obs", + "documenttype":"sdk-nodejs-devg" + } + ], + "title":"Change History", + "githuburl":"" + } +] \ No newline at end of file diff --git a/docs/obs_3rd_party/nodejs_sdk/CLASS.TXT.json b/docs/obs_3rd_party/nodejs_sdk/CLASS.TXT.json new file mode 100644 index 000000000..42afb4df2 --- /dev/null +++ b/docs/obs_3rd_party/nodejs_sdk/CLASS.TXT.json @@ -0,0 +1,1100 @@ +[ + { + "desc":"Latest version of OBS Node.js SDK: DownloadRecommended versions: Node 0.12.x, Node4.x, Node6.x, Node8.x, or Node10.xInterface changes: The following table describes the i", + "product_code":"obs", + "title":"Downloading an SDK", + "uri":"obs_29_0001.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"1" + }, + { + "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":"Getting Started", + "uri":"obs_29_0100.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"2" + }, + { + "desc":"Ensure that you are familiar with OBS basic concepts from Help Center, such as bucket, object, region, and AK and SK.You can see General Ways to Use ObsClient to learn ho", + "product_code":"obs", + "title":"Before You Start", + "uri":"obs_29_0101.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"3" + }, + { + "desc":"OBS uses access keys (AK and SK) for signature verification to ensure that only authorized accounts can access specified OBS resources. Detailed explanations are as follo", + "product_code":"obs", + "title":"Creating Access Keys", + "uri":"obs_29_0103.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"4" + }, + { + "desc":"Download the recommended version from the Node.js's official website and install it.Download the latest version of Eclipse IDE for JavaScript and Web Developer from Eclip", + "product_code":"obs", + "title":"Preparing a Development Environment", + "uri":"obs_29_0104.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"5" + }, + { + "desc":"The following procedures use OBS Node.js SDK of the latest version as an example.After the installation, the directory structure is similar to the following:├── examples├", + "product_code":"obs", + "title":"Installing the SDK", + "uri":"obs_29_0105.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"6" + }, + { + "desc":"You can click here to view the endpoints and regions enabled for OBS.The SDK allows you to pass endpoints with or without the protocol name. Suppose the endpoint you obta", + "product_code":"obs", + "title":"Obtaining Endpoints", + "uri":"obs_29_0106.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"7" + }, + { + "desc":"Each time you want to send an HTTP/HTTPS request to OBS, you must create an instance ofObsClient. Sample code is as follows:JavaScript is an asynchronous programming lang", + "product_code":"obs", + "title":"Initializing an Instance of ObsClient", + "uri":"obs_29_0107.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"8" + }, + { + "desc":"A bucket is a global namespace of OBS and is a data container. It functions as a root directory of a file system and can store objects. The following code shows how to cr", + "product_code":"obs", + "title":"Creating a Bucket", + "uri":"obs_29_0108.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"9" + }, + { + "desc":"This example uploads string Hello OBS to bucket examplebucket as object example/objectname.The example code is as follows:For more information, see Object Upload Overview", + "product_code":"obs", + "title":"Uploading an Object", + "uri":"obs_29_0109.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"10" + }, + { + "desc":"This example downloads object example/objectname from bucket examplebucket.The example code is as follows:For more information, see Overview.", + "product_code":"obs", + "title":"Downloading an Object", + "uri":"obs_29_0110.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"11" + }, + { + "desc":"After objects are uploaded, you may want to view the objects contained in a bucket. Sample code is as follows:// Import the OBS library.\n// Use npm to install the client.", + "product_code":"obs", + "title":"Listing Objects", + "uri":"obs_29_0111.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"12" + }, + { + "desc":"This example deletes object example/objectname from bucket examplebucket.The example code is as follows:For more information, see Deleting an Object.", + "product_code":"obs", + "title":"Deleting an Object", + "uri":"obs_29_0112.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"13" + }, + { + "desc":"ObsClient returns the results by using a callback function that contains two parameters in sequence: the exception information parameter and the SDK common result object ", + "product_code":"obs", + "title":"General Ways to Use ObsClient", + "uri":"obs_29_0113.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"2", + "code":"14" + }, + { + "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_29_0200.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"15" + }, + { + "desc":"To use OBS, you need a valid pair of AK and SK for signature authentication.After obtaining the AK and SK, you can create an instance of ObsClient to call SDK APIs.For de", + "product_code":"obs", + "title":"Configuring Access Keys", + "uri":"obs_29_0201.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"15", + "code":"16" + }, + { + "desc":"ObsClient functions as the Node.js client for accessing OBS. It offers callers a series of APIs for interaction with OBS and is used for managing and operating resources,", + "product_code":"obs", + "title":"Creating an Instance of ObsClient", + "uri":"obs_29_0202.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"15", + "code":"17" + }, + { + "desc":"You can set the following initialization parameters to configure an instance of ObsClient.Parameters whose recommended value is N/A need to be set according to the actual", + "product_code":"obs", + "title":"Configuring an Instance of ObsClient", + "uri":"obs_29_0203.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"15", + "code":"18" + }, + { + "desc":"OBS Node.js SDK provides the logging function based on Log4js. You can call ObsClient.initLog to enable and configure logging. The following is a code sample:The logging ", + "product_code":"obs", + "title":"Configuring SDK Logging", + "uri":"obs_29_0204.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"15", + "code":"19" + }, + { + "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_29_0300.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"20" + }, + { + "desc":"OBS buckets are containers for storing objects you upload to OBS. This API creates a bucket.When creating a bucket, you can also configure parameters such as the storage ", + "product_code":"obs", + "title":"Creating a Bucket", + "uri":"obs_29_0301.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"21" + }, + { + "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":"Listing Buckets", + "uri":"obs_29_0302.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"22" + }, + { + "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_29_0304.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"23" + }, + { + "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_29_0303.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"24" + }, + { + "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_29_0305.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"25" + }, + { + "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 a Bucket ACL", + "uri":"obs_29_0306.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"26" + }, + { + "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_29_0307.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"27" + }, + { + "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_29_0308.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"28" + }, + { + "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_29_0309.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"29" + }, + { + "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_29_0310.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"30" + }, + { + "desc":"This API returns the region of a bucket.To obtain the region of a bucket, you must be the bucket owner or have the required permission (obs:bucket:GetBucketLocation in IA", + "product_code":"obs", + "title":"Obtaining the Region of a Bucket", + "uri":"obs_29_0311.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"31" + }, + { + "desc":"This API returns the storage information on 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_29_0312.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"32" + }, + { + "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 for a Bucket", + "uri":"obs_29_0313.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"33" + }, + { + "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 storage q", + "product_code":"obs", + "title":"Obtaining the Storage Quota of a Bucket", + "uri":"obs_29_0314.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"34" + }, + { + "desc":"This API configures a storage class for a bucket. If you upload or copy objects to a bucket with a storage class configured or initiating a multipart upload for such a bu", + "product_code":"obs", + "title":"Configuring a Storage Class for a Bucket", + "uri":"obs_29_0315.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"35" + }, + { + "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_29_0316.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"20", + "code":"36" + }, + { + "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_29_0400.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"37" + }, + { + "desc":"In OBS, objects are basic data units that users can perform operations on. OBS Node.js SDK provides abundant APIs for object upload in the following methods:Uploading an ", + "product_code":"obs", + "title":"Object Upload Overview", + "uri":"obs_29_0401.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"38" + }, + { + "desc":"This API uploads an object to a bucket.To upload an object, you must be the bucket owner or have the required permission (obs:object:PutObject in IAM or PutObject in a bu", + "product_code":"obs", + "title":"Uploading an Object - Text-Based", + "uri":"obs_29_0402.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"39" + }, + { + "desc":"This API uploads an object to a bucket.To upload an object, you must be the bucket owner or have the required permission (obs:object:PutObject in IAM or PutObject in a bu", + "product_code":"obs", + "title":"Uploading an Object - Streaming", + "uri":"obs_29_0403.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"40" + }, + { + "desc":"This API uploads an object to a bucket.To upload an object, you must be the bucket owner or have the required permission (obs:object:PutObject in IAM or PutObject in a bu", + "product_code":"obs", + "title":"Uploading an Object - File-Based", + "uri":"obs_29_0404.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"41" + }, + { + "desc":"This API uploads a folder object to a bucket to make it easy to manage data stored in the bucket.To upload an object, you must be the bucket owner or have the required pe", + "product_code":"obs", + "title":"Creating a Folder", + "uri":"obs_29_0405.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"42" + }, + { + "desc":"Object metadata contains a set of name-value pairs that are used for describing and managing objects.Currently, only the system-defined metadata is supported. System-defi", + "product_code":"obs", + "title":"Configuring Object Metadata", + "uri":"obs_29_0406.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"43" + }, + { + "desc":"When uploading an object or initiating a multipart upload, you can set an expiration time for the object using Expires. This method only supports setting the object expir", + "product_code":"obs", + "title":"Configuring a Lifecycle Rule When Uploading an Object", + "uri":"obs_29_0407.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"44" + }, + { + "desc":"This API uploads a file or folder to an existing OBS bucket. You can upload text, pictures, videos, or any other types of files.This API adds data to the end of a specifi", + "product_code":"obs", + "title":"Uploading an Object - Append", + "uri":"obs_29_0409.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"45" + }, + { + "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_29_0411.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"46" + }, + { + "desc":"Performing a browser-based upload is to upload objects to a specified bucket in HTML form. The maximum size of an object is 5 GB.You can call ObsClient.createPostSignatur", + "product_code":"obs", + "title":"Uploading an Object - Browser-Based", + "uri":"obs_29_0412.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"37", + "code":"47" + }, + { + "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_29_0500.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"48" + }, + { + "desc":"OBS Node.js SDK provides abundant APIs for downloading objects in the following modes:Downloading an Object - Text-BasedDownloading an Object - StreamingDownloading an Ob", + "product_code":"obs", + "title":"Overview", + "uri":"obs_29_0501.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"49" + }, + { + "desc":"This API downloads an object as text from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:GetOb", + "product_code":"obs", + "title":"Downloading an Object - Text-Based", + "uri":"obs_29_0502.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"50" + }, + { + "desc":"This API downloads an object as a stream from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:G", + "product_code":"obs", + "title":"Downloading an Object - Streaming", + "uri":"obs_29_0503.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"51" + }, + { + "desc":"This API downloads an object as a file from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:Get", + "product_code":"obs", + "title":"Downloading an Object - File-Based", + "uri":"obs_29_0504.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"52" + }, + { + "desc":"This API downloads part of an object from OBS to your local computer. If the specified range is from 0 to 1,000, data from byte 0 to byte 1,000, 1,001 bytes in total, are", + "product_code":"obs", + "title":"Downloading an Object - Range-Based", + "uri":"obs_29_0505.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"53" + }, + { + "desc":"This API downloads objects that meet specified conditions from OBS to a local computer.To download an object, you must be the bucket owner or have the required permission", + "product_code":"obs", + "title":"Downloading an Object - Conditional", + "uri":"obs_29_0506.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"54" + }, + { + "desc":"When downloading an object, you can rewrite some HTTP/HTTPS response headers. The following table lists rewritable response headers.This code example rewrites response he", + "product_code":"obs", + "title":"Rewriting Response Headers", + "uri":"obs_29_0507.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"55" + }, + { + "desc":"To prolong the validity period of the Cold data restored, you can repeatedly restore the data, but you will be billed for each restoration. After a second restore, the va", + "product_code":"obs", + "title":"Downloading a Cold Object", + "uri":"obs_29_0509.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"56" + }, + { + "desc":"The API for resumable download is an encapsulated and enhanced version of range-based download. Downloading large files often fails due to an unstable network or program ", + "product_code":"obs", + "title":"Downloading an Object - Resumable", + "uri":"obs_29_0510.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"48", + "code":"57" + }, + { + "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_29_0600.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"58" + }, + { + "desc":"Object metadata contains a set of name-value pairs that are used for describing and managing objects.Currently, system-defined and custom metadata are supported.System-de", + "product_code":"obs", + "title":"Configuring Object Metadata", + "uri":"obs_29_0602.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"59" + }, + { + "desc":"Object metadata contains a set of name-value pairs that are used for describing and managing objects.Currently, only the system-defined metadata is supported. System-defi", + "product_code":"obs", + "title":"Obtaining Object Metadata", + "uri":"obs_29_0601.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"60" + }, + { + "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_29_0604.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"61" + }, + { + "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 the ACL of an Object", + "uri":"obs_29_0603.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"62" + }, + { + "desc":"This API lists some or all of the objects in a bucket. You can configure the prefix, number, or start position as the filter to list objects. Returned objects are listed ", + "product_code":"obs", + "title":"Listing Objects in a Bucket", + "uri":"obs_29_0605.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"63" + }, + { + "desc":"Exercise caution when performing this operation. If the versioning function is disabled for the bucket where the object is located, the object cannot be restored after be", + "product_code":"obs", + "title":"Deleting an Object", + "uri":"obs_29_0606.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"64" + }, + { + "desc":"Exercise caution when performing this operation. If versioning is disabled for the bucket where objects are located, objects cannot be restored after being deleted.This A", + "product_code":"obs", + "title":"Batch Deleting Objects", + "uri":"obs_29_0607.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"65" + }, + { + "desc":"This API copies an object stored in OBS to a specified path. You can copy an object of up to 5 GB in a single operation.To copy an object, you must be the bucket owner or", + "product_code":"obs", + "title":"Copying an Object", + "uri":"obs_29_0608.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"58", + "code":"66" + }, + { + "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_29_1900.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"67" + }, + { + "desc":"To upload a large file, multipart upload is recommended. Multipart upload is applicable to many scenarios. Below are some examples.Files to be uploaded are larger than 10", + "product_code":"obs", + "title":"Multipart Upload APIs", + "uri":"obs_29_1901.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"68" + }, + { + "desc":"This API initiates a multipart upload and returns a globally unique upload ID. You can use this upload ID in your subsequent requests for uploading, assembling, and listi", + "product_code":"obs", + "title":"Initiating a Multipart Upload", + "uri":"obs_29_1902.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"69" + }, + { + "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.When uploading a par", + "product_code":"obs", + "title":"Uploading a Part", + "uri":"obs_29_1903.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"70" + }, + { + "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_29_1904.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"71" + }, + { + "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_29_1905.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"72" + }, + { + "desc":"This API lists multipart uploads that have been initiated but not completed or cancelled.You can list all the multipart uploads that are not assembled or aborted in a buc", + "product_code":"obs", + "title":"Listing Multipart Uploads", + "uri":"obs_29_1906.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"73" + }, + { + "desc":"This API uploads a part for a specified multipart upload by copying data to a specified bucket.After initiating a multipart upload task, you can add parts for this task b", + "product_code":"obs", + "title":"Copying a Part", + "uri":"obs_29_1907.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"74" + }, + { + "desc":"This API aborts a multipart upload by specifying its ID.After a multipart upload is aborted, its upload ID cannot be used to upload any part. And the space occupied by al", + "product_code":"obs", + "title":"Aborting a Multipart Upload", + "uri":"obs_29_1908.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"67", + "code":"75" + }, + { + "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_29_0700.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"76" + }, + { + "desc":"OBS allows you to create a URL whose Query parameters carry authentication information by specifying the AK and SK, HTTP method, and request parameters. You can provide t", + "product_code":"obs", + "title":"Using a Temporary URL for Authorized Access", + "uri":"obs_29_0701.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"76", + "code":"77" + }, + { + "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_29_0800.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"78" + }, + { + "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":"Versioning Overview", + "uri":"obs_29_0801.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"79" + }, + { + "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_29_0802.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"80" + }, + { + "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":"Viewing the Versioning Status of a Bucket", + "uri":"obs_29_0803.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"81" + }, + { + "desc":"This API downloads an object version from OBS to your local computer.To download an object, you must be the bucket owner or have the required permission (obs:object:GetOb", + "product_code":"obs", + "title":"Obtaining an Object Version", + "uri":"obs_29_0804.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"82" + }, + { + "desc":"This API copies an object version in a specified bucket. You can copy an object of up to 5 GB in a single operation.To copy an object, you must be the bucket owner or hav", + "product_code":"obs", + "title":"Copying an Object Version", + "uri":"obs_29_0805.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"83" + }, + { + "desc":"To download an object in the Cold storage class, you need to restore it first. After an object is restored, a copy of the object is saved in the Standard storage class. B", + "product_code":"obs", + "title":"Restoring a Cold Object Version", + "uri":"obs_29_0806.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"84" + }, + { + "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 in a Bucket", + "uri":"obs_29_0807.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"85" + }, + { + "desc":"This API calls ObsClient.setObjectAcl to set an ACL for an object version specified by the VersionId parameter. For details about the API definition, see Configuring an O", + "product_code":"obs", + "title":"Setting an ACL for an Object Version", + "uri":"obs_29_0808.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"86" + }, + { + "desc":"This API calls ObsClient.getObjectAcl to obtain the ACL of an object version specified by the VersionId parameter. For details about the API definition, see Obtaining the", + "product_code":"obs", + "title":"Obtaining the ACL of an Object Version", + "uri":"obs_29_1308.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"87" + }, + { + "desc":"You can call ObsClient.deleteObject to delete an object version specified by the VersionId parameter. For details about the API definition, see Deleting an Object.You can", + "product_code":"obs", + "title":"Deleting an Object Version", + "uri":"obs_29_0809.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"78", + "code":"88" + }, + { + "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", + "uri":"obs_29_0900.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"89" + }, + { + "desc":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API configures lifecycle rules for a bucket.Expired ob", + "product_code":"obs", + "title":"Configuring Lifecycle Rules for a Bucket", + "uri":"obs_29_0902.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"89", + "code":"90" + }, + { + "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 the Lifecycle Rules of a Bucket", + "uri":"obs_29_0903.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"89", + "code":"91" + }, + { + "desc":"You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.This API deletes the lifecycle rules of a bucket.To delete ", + "product_code":"obs", + "title":"Deleting the Lifecycle Rules of a Bucket", + "uri":"obs_29_0904.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"89", + "code":"92" + }, + { + "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 CORS", + "uri":"obs_29_1000.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "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 CORS for a Bucket", + "uri":"obs_29_1002.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"93", + "code":"94" + }, + { + "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":"Obtaining the CORS Configuration of a Bucket", + "uri":"obs_29_1003.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"93", + "code":"95" + }, + { + "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":"Deleting the CORS Configuration of a Bucket", + "uri":"obs_29_1004.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"93", + "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_29_1100.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"97" + }, + { + "desc":"A bucket in the Warm or Cold storage class cannot be used as a log target bucket.This API enables logging for a bucket (source) and configures another bucket (target) to ", + "product_code":"obs", + "title":"Configuring Logging for a Bucket", + "uri":"obs_29_1102.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"97", + "code":"98" + }, + { + "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_29_1103.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"97", + "code":"99" + }, + { + "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_29_1200.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"100" + }, + { + "desc":"You can upload the content files of the static website to your bucket in OBS as objects and configure the public-read permission on the files, and then configure the stat", + "product_code":"obs", + "title":"Overview", + "uri":"obs_29_1201.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"100", + "code":"101" + }, + { + "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_29_1203.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"100", + "code":"102" + }, + { + "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_29_1204.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"100", + "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":"Deleting Website Hosting Settings", + "uri":"obs_29_1205.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"100", + "code":"104" + }, + { + "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":"Tagging", + "uri":"obs_29_1300.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"105" + }, + { + "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":"Setting Bucket Tags", + "uri":"obs_29_1302.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"105", + "code":"106" + }, + { + "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_29_1303.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"105", + "code":"107" + }, + { + "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_29_1304.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"105", + "code":"108" + }, + { + "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_29_1500.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"109" + }, + { + "desc":"The following table lists APIs related to server-side encryption:OBS Node.js SDK supports the following two types of encryption/decryption mode:", + "product_code":"obs", + "title":"APIs", + "uri":"obs_29_1502.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"109", + "code":"110" + }, + { + "desc":"This example uploads object example/objectname to bucket examplebucket and encrypts it using SSE-C.This example downloads the encrypted object example/objectname using a ", + "product_code":"obs", + "title":"Code Examples", + "uri":"obs_29_1503.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"109", + "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":"Troubleshooting", + "uri":"obs_29_1600.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"112" + }, + { + "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_29_1601.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"112", + "code":"113" + }, + { + "desc":"After you call an API in an instance of the ObsClient class, a common result object will be returned if no exception is thrown. The following table lists the fields of th", + "product_code":"obs", + "title":"SDK Common Results", + "uri":"obs_29_1602.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"112", + "code":"114" + }, + { + "desc":"OBS Node.js SDK provides the logging function based on Log4js. You can call ObsClient.initLogto enable and configure logging. The sample code is as follows:The logging fu", + "product_code":"obs", + "title":"Log Analysis", + "uri":"obs_29_1603.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"112", + "code":"115" + }, + { + "desc":"Problem: When OBS Node.js SDK is used for secondary development, an error message was displayed indicating that a module was missing, for example, \"Cannot find module 'xm", + "product_code":"obs", + "title":"Missing Modules", + "uri":"obs_29_1604.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"112", + "code":"116" + }, + { + "desc":"Problem: If a \"connect ETIMEDOUT\" error occurred when calling an API, the possible cause was that the service address (endpoint) was incorrect or the network was disconne", + "product_code":"obs", + "title":"Connection Timeout", + "uri":"obs_29_1605.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"112", + "code":"117" + }, + { + "desc":"Problem: The HTTP status code obtained from CommonMsg.Status was 403, and the OBS server-side error code obtained from CommonMsg.Code was SignatureDoesNotMatch.Solution:C", + "product_code":"obs", + "title":"Unmatched Signatures", + "uri":"obs_29_1606.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"112", + "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":"FAQs", + "uri":"obs_29_1700.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"119" + }, + { + "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_29_1715.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"119", + "code":"120" + }, + { + "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_29_1716.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"119", + "code":"121" + }, + { + "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_29_1802.html", + "doc_type":"sdk-nodejs-devg", + "p_code":"", + "code":"122" + } +] \ No newline at end of file diff --git a/docs/obs_3rd_party/nodejs_sdk/PARAMETERS.txt b/docs/obs_3rd_party/nodejs_sdk/PARAMETERS.txt new file mode 100644 index 000000000..6da8d5f07 --- /dev/null +++ b/docs/obs_3rd_party/nodejs_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/nodejs_sdk/obs_29_0001.html b/docs/obs_3rd_party/nodejs_sdk/obs_29_0001.html new file mode 100644 index 000000000..38476c444 --- /dev/null +++ b/docs/obs_3rd_party/nodejs_sdk/obs_29_0001.html @@ -0,0 +1,84 @@ + + +
Interface + |
+Description + |
+
|---|---|
ObsClient.listBuckets + |
+In the response, the data type of InterfaceResult.Buckets was changed to Array. InterfaceResult.Buckets.Bucket was deleted. + |
+
ObsClient.setBucketAcl + |
+In the request, the data type of Grants was changed to Array. Grants.Grant was deleted. + |
+
ObsClient.getBucketAcl + |
+In the response, the data type of InterfaceResult.Grants was changed to Array. InterfaceResult.Grants.Grant was deleted. + |
+
ObsClient.setObjectAcl + |
+In the request, the data type of Grants was changed to Array. Grants.Grant was deleted. + |
+
ObsClient.getObjectAcl + |
+In the response, the data type of InterfaceResult.Grants was changed to Array. InterfaceResult.Grants.Grant was deleted. + |
+
ObsClient.setBucketLogging + |
+In the request, the data type of LoggingEnabled.TargetGrants was changed to Array. LoggingEnabled.TargetGrants.Grant was deleted. + |
+
ObsClient.getBucketLogging + |
+In the response, the data type of InterfaceResult.LoggingEnabled.TargetGrants was changed to Array. InterfaceResult.LoggingEnabled.TargetGrants.Grant was deleted. + |
+
ObsClient.setBucketWebsite + |
+In the request, the data type of RoutingRules was changed to Array. RoutingRules.RoutingRule was deleted. + |
+
ObsClient.getBucketWebsite + |
+In the response, the data type of InterfaceResult.RoutingRules was changed to Array. InterfaceResult.RoutingRules.RoutingRule was deleted. + |
+
ObsClient.setBucketCors + |
+In the request, CorsRule was renamed as CorsRules. + |
+
ObsClient.getBucketCors + |
+In the response, InterfaceResult.CorsRule was renamed as InterfaceResult.CorsRules. + |
+
ObsClient.setBucketTagging + |
+In the request, the data type of TagSet was changed to Array. TagSet.Tag was deleted. + |
+
ObsClient.getBucketTagging + |
+In the response, the data type of InterfaceResult.TagSet was changed to Array. InterfaceResult.TagSet.Tag was deleted. + |
+
OBS uses access keys (AK and SK) for signature verification to ensure that only authorized accounts can access specified OBS resources. Detailed explanations are as follows:
+The procedure is as follows:
+
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.
+The following procedures use OBS Node.js SDK of the latest version as an example.
+
After the installation, the directory structure is similar to the following:
+├── examples
+├── lib
+├── node_modules
+├── package.json
+└── README.txt
+
The SDK allows you to pass endpoints with or without the protocol name. Suppose the endpoint you obtained is your-endpoint. The endpoint passed when initializing an instance of ObsClient can be http://your-endpoint, https://your-endpoint, or your-endpoint.
+Each time you want to send an HTTP/HTTPS request to OBS, you must create an instance of ObsClient. Sample code is as follows:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Use the instance to access OBS.
+
+// Close the ObsClient instance.
+// obsClient.close();
+
A bucket is a global namespace of OBS and is a data container. It functions as a root directory of a file system and can store objects. The following code shows how to create a bucket:
+
This example uploads string Hello OBS to bucket examplebucket as object example/objectname.
+The example code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify a text object. + Body : 'Hello OBS' + }; + // Upload the object. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put object(%s) under the bucket(%s) successful!!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("StorageClass:%s, ETag:%s", result.InterfaceResult.StorageClass, result.InterfaceResult.ETag); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +putObject(); + |
This example downloads object example/objectname from bucket examplebucket.
+The example code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + }; + + // Download the object as text. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Object Content: %s', result.InterfaceResult.Content); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // List objects in a bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
This example deletes object example/objectname from bucket examplebucket.
+The example code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example) to delete. + Key: 'example/objectname', + }; + // Delete the object. + const result = await obsClient.deleteObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteObject(); + |
ObsClient returns the results by using a callback function that contains two parameters in sequence: the exception information parameter and the SDK common result object parameter. If the exception information parameter in the callback function is not null, an error occurs during the API calling. Otherwise, the API is called. In such conditions, you need to obtain the HTTP status code from the SDK common result object parameter to check whether the operation is successful. Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Construct request parameters for bucket operations.
+var requestParam1 = {
+ Bucket : 'bucketname'
+ // Other fields.
+};
+
+var callback1 = (err, result) => {
+ // Process the result of a bucket-related API call.
+};
+
+// Call the APIs for bucket operations, such as creating a bucket.
+obsClient.createBucket(requestParam1, callback1);
+
+// Construct request parameters for object operations.
+var requestParam2 = {
+ Bucket : 'bucketname',
+ Key : 'objectname'
+ // Other fields.
+};
+
+var callback2 = (err, result) => {
+ // Process the result of an object-related API call.
+};
+
+// Call an object-related API, such as the API for downloading an object.
+obsClient.getObject(requestParam2, callback2);
+
For APIs used for bucket operations, the Bucket parameter contained in the request object indicates the bucket name. For APIs used for object operations, the Bucket and Key parameters contained in the request object specify the bucket name and object name, respectively.
+Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Call APIs to perform operations, such as uploading an object.
+obsClient.putObject({
+ Bucket : 'bucketname',
+ Key : 'objectname',
+ Body : 'Hello OBS'
+}, (err, result) => {
+ // If the err parameter is not null, an error occurs during the API calling.
+ if(err){
+ console.log('Error-->' + err);
+ }else{
+ // If the exception information is null, the API call is complete. In such conditions, you need to check the HTTP status code.
+ if(result.CommonMsg.Status < 300){// The operation is successful.
+ if(result.InterfaceResult){
+ // Process the business logic after the operation is successful.
+ };
+ }else{// The operation fails. Obtain details about the exception.
+ console.log('Code-->' + result.CommonMsg.Code);
+ console.log('Message-->' + result.CommonMsg.Message);
+ console.log('HostId-->' + result.CommonMsg.HostId);
+ console.log('RequestId-->' + result.CommonMsg.RequestId);
+ };
+ };
+});
+ObsClient supports results returned via the Promise object. If no exception is caught by the catch method of the Promise object, the API calling is complete. In such conditions, you need to obtain the HTTP status code from the SDK Common Result Object to check whether the operation is successful. The following is a code sample:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+
+// Construct request parameters for bucket operations.
+var requestParam1 = {
+ Bucket : 'bucketname'
+ // Other fields.
+};
+
+// Call the APIs for bucket operations, such as creating a bucket.
+var promise1 = obsClient.createBucket(requestParam1);
+promise1.then((result) => {
+ // Process the API call result.
+}).catch((err)=>{
+ // Rectify the fault.
+});
+
+// Construct request parameters for object operations.
+var requestParam2 = {
+ Bucket : 'bucketname',
+ Key : 'objectname'
+ // Other fields.
+};
+
+// Call an object-related API, such as the API for downloading an object.
+var promise2 = obsClient.getObject(requestParam2);
+promise2.then((result) => {
+ // Process the API call result.
+}).catch((err)=>{
+ // Rectify the fault.
+});
+
For APIs used for bucket operations, the Bucket parameter contained in the request object indicates the bucket name. For APIs used for object operations, the Bucket and Key parameters contained in the request object specify the bucket name and object name, respectively.
+Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Call APIs to perform operations, such as uploading an object.
+obsClient.putObject({
+ Bucket : 'bucketname',
+ Key : 'objectname',
+ Body : 'Hello OBS'
+}).then((result) => {
+ // If no exception occurs and the API call is complete, check the HTTP status code.
+ if(result.CommonMsg.Status < 300){// Operation succeeded
+ if(result.InterfaceResult){
+ // Process the business logic after the operation is successful.
+ };
+}else{// The operation fails. Obtain details about the exception.
+ console.log('Code-->' + result.CommonMsg.Code);
+ console.log('Message-->' + result.CommonMsg.Message);
+ console.log('HostId-->' + result.CommonMsg.HostId);
+ console.log('RequestId-->' + result.CommonMsg.RequestId);
+ };
+}).catch((err) => {
+ // An exception occurred after the API is called.
+ console.error('Error-->' + err);
+});
+To use OBS, you need a valid pair of AK and SK for signature authentication.
+After obtaining the AK and SK, you can create an instance of ObsClient to call SDK APIs.
+For details, see Creating Access Keys.
+After obtaining the AK and SK, you can follow these steps to start initialization:
+ +ObsClient functions as the Node.js client for accessing OBS. It offers callers a series of APIs for interaction with OBS and is used for managing and operating resources, such as buckets and objects, stored in OBS. To use OBS Node.js SDK to send a request to OBS, you need to initialize an instance of ObsClient and modify parameters related to initial configurations of the instance based on actual needs.
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Use the instance to access OBS.
+
+// Close the ObsClient instance.
+// obsClient.close();
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Use the instance to access OBS.
+
+// Close the ObsClient instance.
+// obsClient.close();
+// Import the OBS library.
+// Use npm to install the client.
+var ObsClient = require('esdk-obs-nodejs');
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Initialize an ObsClient instance by using the factory method.
+var obsClient = new ObsClient();
+obsClient.factory({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Use the instance to access OBS.
+
+// Close the ObsClient instance.
+// obsClient.close();
+// Import the OBS library.
+// Use npm to install the client.
+var ObsClient = require('esdk-obs-nodejs');
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Initialize an ObsClient instance by using the factory method.
+var obsClient = new ObsClient();
+obsClient.factory({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Use the instance to access OBS.
+
+// Close the ObsClient instance.
+// obsClient.close();
+
You can set the following initialization parameters to configure an instance of ObsClient.
+ +Parameter + |
+Description + |
+Recommended Value + |
+
|---|---|---|
access_key_id + |
+AK + |
+N/A + |
+
secret_access_key + |
+SK + |
+N/A + |
+
server + |
+Endpoint for accessing OBS, which contains the protocol type, domain name (or IP address), and port number. For example, https://your-endpoint:443. For security purposes, you are advised to use HTTPS. + |
+N/A + |
+
max_retry_count + |
+Maximum number of retries when an HTTP/HTTPS connection is abnormal. The default value is 3. + |
+[1, 5] + |
+
timeout + |
+Timeout period (in seconds) of an HTTP/HTTPS request. The default value is 60. + |
+[10, 60] + |
+
ssl_verify + |
+Whether to verify server-side certificates. Possible values are: +
The default value is false. + |
+N/A + |
+
long_conn_param + |
+Persistent connection mode (in seconds). If the value is equal to or larger than 0, the persistent connection mode is enabled and this value is used as the initial delay of the TCP Keep-Alive packets. +By default, this parameter is left blank, which indicates that persistent connection mode is disabled. + |
+N/A + |
+
is_cname + |
+Whether to use self-defined domain name to access OBS. The default value is false. + |
+N/A + |
+
OBS Node.js SDK provides the logging function based on Log4js. You can call ObsClient.initLog to enable and configure logging. The following is a code sample:
+obsClient.initLog({
+file_full_path:'./logs/OBS-SDK.log', //Set the path to the log file.
+ max_log_size:20480, //Set the size of the log file, in bytes.
+ backups:10, //Set the maximum number of log files that can be stored.
+ level:'warn', //Set the log level.
+ log_to_console:true //Set whether to print the log to console.
+});
+
OBS buckets are containers for storing objects you upload to OBS. This API creates a bucket.
+When creating a bucket, you can also configure parameters such as the storage class, region, and access control list (ACL) as needed.
+ObsClient.createBucket(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Location + |
+string + |
+Yes if the OBS service region is not the default region + |
+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. + |
+
ACL + |
++ | +No + |
+Explanation: +ACL that can be pre-defined when a bucket is created. +Restrictions: +None +Value range: +For details about the ACL options, see AclType. +Default value: +private + |
+
StorageClass + |
++ | +No + |
+Explanation: +Bucket storage class that can be specified at bucket creation. +Restrictions: +None +Value range: +See StorageClassType. +Default value: +STANDARD + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can list objects, multipart uploads, and object versions in the bucket you are creating, as well as obtain bucket metadata. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
GrantWrite + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE permission is granted to. The account with the WRITE permission can create, delete, and overwrite objects in the bucket you are creating; initiate or abort multipart uploads; and upload, copy, and assemble parts. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
GrantReadACP + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the bucket you are creating. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
GrantWriteACP + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the bucket you are creating. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can perform any operation on the bucket you are creating. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
GrantReadDelivered + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. By default, this READ permission applies to all objects in the bucket. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
GrantFullControlDelivered + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission has full control over the bucket you are creating. By default, the FULL_CONTROL permission applies to all objects in the bucket. +Restrictions: +None +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID?. +Default value: +None + |
+
MultiEnterprise + |
+string + |
+No + |
+Explanation: +Enterprise project ID that can be specified during 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. epid is not required if you have not enabled EPS yet. +Example: 9892d768-2d13-450f-aac7-ed0e44c2585f +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example creates a bucket named examplebucket. For bucket details, see the code comments below.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an ObsClient instance. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function createBucket() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the region where the bucket is to be created. The region must be the same as that in the passed endpoint. + // Location: "region", + // Specify the bucket ACL. The following uses obs.AclPrivate as an example. + ACL: obsClient.enums.AclPrivate, + // Specify the storage class of the bucket. obs.StorageClassWarm (Warm) is used as an example. If this parameter is not specified, the bucket is created with the Standard storage class. + StorageClass: obsClient.enums.StorageClassWarm, + }; + // Create a bucket. + const result = await obsClient.createBucket(params); + if (result.CommonMsg.Status <= 300) { + console.log("Create bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +createBucket(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
QueryLocation + |
+boolean + |
+No + |
+Explanation: +Whether to query the bucket location +Restrictions: +None +Value range: +
Default value: +false + |
+
Constant + |
+Description + |
+
|---|---|
OBJECT + |
+An object bucket + |
+
POSIX + |
+A parallel file system (POSIX) + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server +Default value: +None + |
+
Owner + |
++ | +Explanation: +Bucket owner +Value range: +See Table 7. + |
+
Buckets + |
+Bucket[] + |
+Explanation: +Bucket information list +Value range: +See Table 8. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
BucketName + |
+string + |
+Explanation: +Bucket name. +Restrictions: +
Default value: +None + |
+
CreationDate + |
+string + |
+Explanation: +When the bucket was created. +Default value: +None + |
+
Location + |
+string + |
+Explanation: +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. + |
+
You can call ObsClient.listBuckets to list buckets. This example lists all buckets.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listBuckets() { + try { + const params = { + // Specify whether to query the bucket location in the listing. The default value is false. true is used in this example. + QueryLocation: true, + // Specify a bucket type (object buckets in this example). If this parameter is not specified, object buckets and parallel file systems are listed by default. + BucketType: "OBJECT", + }; + // List buckets. + const result = await obsClient.listBuckets(params); + if (result.CommonMsg.Status <= 300) { + console.log("List buckets successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Owner:'); + console.log('ID: %s', result.InterfaceResult.Owner.ID); + console.log('Name: %s', result.InterfaceResult.Owner.Name); + console.log('Buckets:'); + for (let i = 0; i < result.InterfaceResult.Buckets.length; i++) { + const val = result.InterfaceResult.Buckets[i]; + console.log("Bucket[%d]-Name:%s,CreationDate:%s,Location: %s", + i, val.BucketName, val.CreationDate, val.Location); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listBuckets(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.deleteBucket to delete a bucket. 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteBucket() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Delete a bucket. + const result = await obsClient.deleteBucket(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteBucket(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.headBucket to check for a bucket. Sample code is as follows:
+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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function headBucket() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Check whether the bucket exists. + const result = await obsClient.headBucket(params); + if (result.CommonMsg.Status <= 300) { + console.log("Head bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +headBucket(); + |
This API returns information about a bucket, including the storage class, region, CORS rules, and redundancy policy.
+ObsClient.getBucketMetadata(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server +Default value: +None + |
+
StorageClass + |
++ | +Explanation: +Storage class of the bucket. +Value range: +See Table 6. +Default value: +If the storage class of the bucket is Standard, this parameter is not specified. + |
+
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 + |
+
AllowOrigin + |
+string + |
+Explanation: +If Origin in the request meets the CORS rules of the bucket, AllowedOrigin specified in the CORS rules is returned. AllowedOrigin indicates the origin from which requests can access the bucket. +Restrictions: +Domain name of the origin. Each origin can contain at most one wildcard character (*). Example: https://*.vbs.example.com +Default value: +None + |
+
AllowHeader + |
+string + |
+Explanation: +If RequestHeader in the request meets the CORS rules of the bucket, AllowedHeader specified in the CORS rules is returned. AllowedHeader indicates the allowed headers for cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Default value: +None + |
+
AllowMethod + |
+string + |
+Explanation: +AllowedMethod in the CORS rules of the bucket. It specifies the HTTP method allowed for cross-origin requests, that is, the operation type of buckets and objects. +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
ExposeHeader + |
+string + |
+Explanation: +ExposeHeader in the CORS rules of the bucket. It specifies 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 a list of the allowed additional headers. +Restrictions: +Spaces, asterisks (*), ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Default value: +None + |
+
MaxAgeSeconds + |
+number + |
+Explanation: +MaxAgeSeconds in the CORS rules of the bucket. It specifies the time your client can cache the response for a cross-origin request. +Restrictions: +Each CORS rule can contain at most one MaxAgeSeconds. +Value range: +0 to (231 – 1), in seconds +Default value: +100 + |
+
MultiEnterprise + |
+string + |
+Explanation: +Enterprise project ID that can be specified during 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. epid is not required if you have not enabled EPS yet. +Example: 9892d768-2d13-450f-aac7-ed0e44c2585f +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
You can call ObsClient.getBucketMetadata to obtain the metadata of a bucket. This example uses 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketMetadata() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket metadata. + const result = await obsClient.getBucketMetadata(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s metadata successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('StorageClass: %s', result.InterfaceResult.StorageClass); + console.log('Location: %s', result.InterfaceResult.Location); + console.log('Epid: %s', result.InterfaceResult.Epid); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; +getBucketMetadata(); + |
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 modifies a bucket ACL.
+ObsClient.setBucketAcl(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Pre-defined ACL. +Restrictions: +You must specify either ACL or the combination of Owner and Grants. +Value range: +See Table 2. +Default value: +None + |
+
Owner + |
++ | +No + |
+Explanation: +Bucket owner +Restrictions: +
Value range: +See Table 3. +Default value: +None + |
+
Grants + |
+Grant[] + |
+No + |
+Explanation: +Grantees and permissions +Restrictions: +
Value range: +See Table 4. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Grantee + |
++ | +Yes if used as a request parameter + |
+Explanation: +Grantee information. For details, see Table 5. + |
+
Permission + |
++ | +Yes if used as a request parameter + |
+Explanation: +Granted permission +Value range: +See Table 8. +Default value: +None + |
+
Delivered + |
+boolean + |
+No + |
+Explanation: +Whether the ACL of the bucket applies to its objects +Value range: +
Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Type + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Grantee type +Value range: +See Table 6. +Default value: +None + |
+
ID + |
+string + |
+Yes if this parameter is used as a request parameter and Type is set to a user + |
+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 + |
+
Name + |
+string + |
+No if used as a request parameter + |
+Explanation: +Account name of the grantee +Restrictions: +
Default value: +None + |
+
URI + |
++ | +Yes if this parameter is used as a request parameter and Type is set to a group + |
+Explanation: +Authorized user group +Value range: +See Table 7. +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
Group + |
+Grants permissions to user groups. + |
+
CanonicalUser + |
+Grants permissions to individual users. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.GroupAllUsers + |
+AllUsers + |
+All users. + |
+
ObsClient.enums.GroupAuthenticatedUsers + |
+AuthenticatedUsers + |
+Authorized users. This constant is deprecated. + |
+
ObsClient.enums.GroupLogDelivery + |
+LogDelivery + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.PermissionRead + |
+READ + |
+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. + |
+
ObsClient.enums.PermissionWrite + |
+WRITE + |
+A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not applicable to objects. + |
+
ObsClient.enums.PermissionReadAcp + |
+READ_ACP + |
+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. + |
+
ObsClient.enums.PermissionWriteAcp + |
+WRITE_ACP + |
+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. + |
+
ObsClient.enums.PermissionFullControl + |
+FULL_CONTROL + |
+A grantee with this permission for a bucket has PermissionRead, PermissionWrite, PermissionReadAcp, and PermissionWriteAcp permissions for the bucket. +A grantee with this permission for an object has PermissionRead, PermissionReadAcp, and PermissionWriteAcp permissions for the object. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 10. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 11. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 12. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example sets a pre-defined ACL (private read and write) when 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an ObsClient instance. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function createBucket() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the region where the bucket is to be created. The region must be the same as that in the passed endpoint. + // Location: "region", + // Specify the ACL. obs.AclPrivate is used as an example. + ACL: obsClient.enums.AclPrivate, + }; + // Create a bucket. + const result = await obsClient.createBucket(params); + if (result.CommonMsg.Status <= 300) { + console.log("Create bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +createBucket(); + |
This example sets an ACL (private) 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Set the bucket ACL to be private. + ACL: obsClient.enums.AclPrivate + }; + // Set the bucket ACL. + const result = await obsClient.setBucketAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s acl successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketAcl(); + |
This example sets an ACL to allow all users to read from bucket examplebucket but only allow user 0a03f5833900d3730f13c00f49d5exxx to write to 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the bucket owner ID. ownerid is used in this example. + Owner: { ID: 'ownerid' }, + Grants: [ + // Grant the public-read permission to all users. + { Grantee: { Type: 'Group', URI: obsClient.enums.GroupAllUsers }, Permission: obsClient.enums.PermissionRead }, + // Grant the write permission to a specific user. In this example, the user ID is 0a03f5833900d3730f13c00f49d5exxx. + { Grantee: { Type: 'CanonicalUser', ID: '0a03f5833900d3730f13c00f49d5exxx' }, Permission: obsClient.enums.PermissionWrite }, + ] + }; + // Set the bucket ACL. + const result = await obsClient.setBucketAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s acl successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketAcl(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Owner + |
++ | +Explanation: +Account ID of the bucket owner. For details, see Table 6. + |
+
Grants + |
+Grant[] + |
+Explanation: +Grantees' permission information. For details, see Table 7. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Grantee + |
++ | +Explanation: +Grantee information. For details, see Table 8. + |
+
Permission + |
+string + |
+Explanation: +Granted permissions. For details, see Table 11. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Type + |
+string + |
+Explanation: +Grantee type. For details, see Table 9. + |
+
ID + |
+string + |
+Explanation: +Account (domain) ID of the grantee. + |
+
Name + |
+string + |
+Explanation: +Account name of the grantee + |
+
URI + |
+string + |
+Explanation: +Authorized user group. For details, see Table 10. + |
+
Constant + |
+Description + |
+
|---|---|
Group + |
+Grants permissions to user groups. + |
+
CanonicalUser + |
+Grants permissions to individual users. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.GroupAllUsers + |
+AllUsers + |
+All users. + |
+
ObsClient.enums.GroupAuthenticatedUsers + |
+AuthenticatedUsers + |
+Authorized users. This constant is deprecated. + |
+
ObsClient.enums.GroupLogDelivery + |
+LogDelivery + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.PermissionRead + |
+READ + |
+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. + |
+
ObsClient.enums.PermissionWrite + |
+WRITE + |
+A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not applicable to objects. + |
+
ObsClient.enums.PermissionReadAcp + |
+READ_ACP + |
+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. + |
+
ObsClient.enums.PermissionWriteAcp + |
+WRITE_ACP + |
+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. + |
+
ObsClient.enums.PermissionFullControl + |
+FULL_CONTROL + |
+A grantee with this permission for a bucket has PermissionRead, PermissionWrite, PermissionReadAcp, and PermissionWriteAcp permissions for the bucket. +A grantee with this permission for an object has PermissionRead, PermissionReadAcp, and PermissionWriteAcp permissions for the object. + |
+
This example returns the ACL 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket ACL. + const result = await obsClient.getBucketAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s acl rules successful!", params.Bucket); + console.log('RequestId: %s', result.InterfaceResult.RequestId); + console.log('Owner[ID]: %s', result.InterfaceResult.Owner.ID); + console.log('Grants:'); + for (let i = 0; i < result.InterfaceResult.Grants.length; i++) { + const grant = result.InterfaceResult.Grants[i]; + console.log("Grant[%d]-Type:%s, ID:%s, URI:%s, Permission:%s", + i, grant.Grantee.Type, grant.Grantee.ID, grant.Grantee.URI, grant.Permission + ); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketAcl(); + |
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 is applied to a configured bucket and the objects in it. You can use a bucket policy to grant permission for the bucket and the objects in it 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.
+This API configures a policy for a bucket.
+ObsClient.setBucketPolicy(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Policy + |
+string + |
+Yes + |
+Explanation: +Policy in JSON format +Restrictions: +
Value range: +See . +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. +For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.setBucketPolicy to set a bucket policy. 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketPolicy() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify a bucket policy. + Policy: "{\"Statement\":[{\"Sid\":\"Custom-policy-2482\",\"Effect\":\"Allow\",\"Principal\":{\"ID\":[\"*\"]},\"Action\":[\"*\",\"ListBucket\"],\"Resource\":[\"examplebucket\"]}]}", + }; + // Set a bucket policy. + const result = await obsClient.setBucketPolicy(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s policy successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketPolicy(); + |
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 is applied to a configured bucket and the objects in it. You can use a bucket policy to grant permission for the bucket and the objects in it 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.
+This API returns the policy of a bucket.
+ObsClient.getBucketPolicy(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Policy + |
+string + |
+Explanation: +Policy in JSON format +Restrictions: +
|
+
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketPolicy() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket policy. + const result = await obsClient.getBucketPolicy(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s policy successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("Policy: %s", result.InterfaceResult.Policy); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketPolicy(); + |
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 is applied to a configured bucket and the objects in it. You can use a bucket policy to grant permission for the bucket and the objects in it 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.
+This API deletes 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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteBucketPolicy() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Delete a bucket policy. + const result = await obsClient.deleteBucketPolicy(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s policy successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("Delete bucket(%s)'s policy fail!", params.Bucket); + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteBucketPolicy(); + |
This API returns the region of a bucket.
+ObsClient.getBucketLocation(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
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. + |
+
You can call ObsClient.getBucketLocation to obtain the location of a bucket. This example uses 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketLocation() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket region. + const result = await obsClient.getBucketLocation(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s location successful!", params.Bucket); + console.log('Location: %s', result.InterfaceResult.Location); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketLocation(); + |
This API returns the storage information on 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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Size + |
+number + |
+Explanation: +Size of the space occupied by objects in the bucket. + |
+
ObjectNumber + |
+number + |
+Explanation: +Number of objects in the bucket. + |
+
A bucket's storage information comprises its used size and object count. You can call ObsClient.getBucketStorageInfo to obtain the bucket storage information. This example uses 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketStorageInfo() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket storage information. + const result = await obsClient.getBucketStorageInfo(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s storage-info successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Size: %s', result.InterfaceResult.Size); + console.log('ObjectNumber: %s', result.InterfaceResult.ObjectNumber); + return; + }; + + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketStorageInfo(); + |
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. If the storage quota is 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, you can upload new objects only by deleting some existing objects until the used space is less than the quota.
+ObsClient.setBucketQuota(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
StorageQuota + |
+number + |
+Yes + |
+Explanation: +Bucket quota. +Restrictions: +None +Value range: +0 to (263 – 1), in bytes +Default value: +0, indicating that there is no limit on the bucket quota. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.setBucketQuota to configure a storage quota for a bucket. This example sets the quota of bucket examplebucket to 1 GB.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketQuota() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify a quota of 1 GB (measured in bytes) for the bucket. + StorageQuota: 1024 * 1024 * 1024 + }; + // Set the bucket quota. + const result = await obsClient.setBucketQuota(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s quota successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketQuota(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.getBucketQuota to obtain the storage quota of a bucket. This example uses 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketQuota() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket quota. + const result = await obsClient.getBucketQuota(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s quota successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('StorageQuota: %s', result.InterfaceResult.StorageQuota); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketQuota(); + |
This API configures a storage class for a bucket. If you upload or copy objects to a bucket with a storage class configured or initiating a multipart upload for such a bucket without specifying storage classes for objects, those objects inherit the storage class of the bucket.
+ObsClient.setBucketStoragePolicy(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
StorageClass + |
++ | +Yes + |
+Explanation: +Storage class of the bucket. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.setBucketStoragePolicy to specify the storage class for a bucket. This example sets the storage class of bucket examplebucket 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketStoragePolicy() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify a storage class (obsClient.enums.StorageClassWarm in this example) for the bucket. + StorageClass: obsClient.enums.StorageClassWarm + }; + // Configure a storage class for the bucket. + const result = await obsClient.setBucketStoragePolicy(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s storage-class successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketStoragePolicy(); + |
This API returns the storage class of a bucket.
+ObsClient.getBucketStoragePolicy(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
StorageClass + |
++ | +Explanation: +Storage class of the bucket. +Value range: +See Table 6. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
You can call ObsClient.getBucketStoragePolicy to obtain the storage class of a bucket. This example uses 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketStoragePolicy() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the storage class of the bucket. + const result = await obsClient.getBucketStoragePolicy(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s storage-class successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('StorageClass: %s', result.InterfaceResult.StorageClass); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketStoragePolicy(); + |
In OBS, objects are basic data units that users can perform operations on. OBS Node.js 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 at a time cannot be larger than 5 GB. If the file is larger than 5 GB, multipart upload (whose part size 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 levels/object name. If the object resides in the root directory of the bucket, its URL does not contain directory levels.
+This API uploads an object to a bucket.
+ObsClient.putObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Access control list (ACL) that can be pre-defined when an object is created. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +When creating an object, you can use this header to specify the storage class for the object. +Restrictions: +None +Value range: +See Table 3. +Default value: +If this parameter is not specified, the object inherits the storage class of the bucket. + |
+
Body + |
+string | stream.Readable + |
+No + |
+Explanation: +Content of the part to upload, which can be in string or stream.Readable form. +Restrictions: +
Value range: +None +Default value: +None + |
+
SourceFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +
Value range: +None +Default value: +None + |
+
Offset + |
+number + |
+No + |
+Explanation: +Start offset of a part in the source file. +Restrictions: +Offset and SourceFile are used together to specify what data is uploaded from the source file. +Value range: +A non-negative integer smaller than the size of the object to be uploaded, in bytes +Default value: +0 + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the upload progress +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (in seconds). + |
+
ContentMD5 + |
+string + |
+No + |
+Explanation: +Base64-encoded MD5 value of the data to be uploaded. It is used for the OBS server to verify data integrity. +Restrictions: +Base64-encoded, 128-bit MD5 value of the request body. +Value range: +Base64-encoded, 128-bit MD5 value of the request body calculated based on the RFC 1864 standard. +Example: n58IG6hfM7vqI4K0vnWpog== +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +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. + |
+
ContentLength + |
+int64 + |
+No + |
+Explanation: +Size of the object to be uploaded. +Restrictions: +
Value range: +0 GB to 5 GB +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +Currently, only KMS is supported. +Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the current object and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the current object, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the object (calculated from the latest modification time of the object). Expired objects are automatically deleted. +Restrictions: +
Value range: +1 to (263 - 1), in days +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
StorageClass + |
++ | +Explanation: +Object storage class. +Value range: +
|
+
VersionId + |
+string + |
+Explanation: +Object version. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Text-based upload is used to upload character strings. You can call ObsClient.putObject to upload character strings to OBS. This example uploads a text object 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify a text object. + Body : 'Hello OBS' + }; + // Upload the object. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put object(%s) under the bucket(%s) successful!!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("StorageClass:%s, ETag:%s", result.InterfaceResult.StorageClass, result.InterfaceResult.ETag); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +putObject(); + |
This API uploads an object to a bucket.
+ObsClient.putObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Access control list (ACL) that can be pre-defined when an object is created. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +When creating an object, you can use this header to specify the storage class for the object. +Restrictions: +None +Value range: +See Table 3. +Default value: +If this parameter is not specified, the object inherits the storage class of the bucket. + |
+
Body + |
+string | stream.Readable + |
+No + |
+Explanation: +Content of the part to upload, which can be in string or stream.Readable form. +Restrictions: +
Value range: +None +Default value: +None + |
+
SourceFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +
Value range: +None +Default value: +None + |
+
Offset + |
+number + |
+No + |
+Explanation: +Start offset of a part in the source file. +Restrictions: +Offset and SourceFile are used together to specify what data is uploaded from the source file. +Value range: +A non-negative integer smaller than the size of the object to be uploaded, in bytes +Default value: +0 + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the upload progress +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (in seconds). + |
+
ContentMD5 + |
+string + |
+No + |
+Explanation: +Base64-encoded MD5 value of the data to be uploaded. It is used for the OBS server to verify data integrity. +Restrictions: +Base64-encoded, 128-bit MD5 value of the request body. +Value range: +Base64-encoded, 128-bit MD5 value of the request body calculated based on the RFC 1864 standard. +Example: n58IG6hfM7vqI4K0vnWpog== +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +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. + |
+
ContentLength + |
+int64 + |
+No + |
+Explanation: +Size of the object to be uploaded. +Restrictions: +
Value range: +0 GB to 5 GB +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +Currently, only KMS is supported. +Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the current object and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the current object, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the object (calculated from the latest modification time of the object). Expired objects are automatically deleted. +Restrictions: +
Value range: +1 to (263 - 1), in days +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
StorageClass + |
++ | +Explanation: +Object storage class. +Value range: +
|
+
VersionId + |
+string + |
+Explanation: +Object version. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Streaming upload uses stream.Readable as the data source of objects. This example uploads an object to bucket examplebucket using a stream.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getNetWorkStream() { + // Define the network stream URL. + const url = 'https://www.example.com'; + // Import HTTP and HTTPS libraries. + const http = require('http'); + const https = require('https'); + // Choose the corresponding library based on the URL. + const request = url.startsWith('http') ? http : https; + return new Promise((resolve, reject) => { + request.get(url, res => { + if (res.statusCode === 200) { + resolve(res); + } else { + reject(res); + }; + }).on(reject); + }); +}; + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the network flow. + Body: await getNetWorkStream() + }; + // Upload the object using the network stream. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put object(%s) under the bucket(%s) successful!!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("StorageClass:%s, ETag:%s", result.InterfaceResult.StorageClass, result.InterfaceResult.ETag); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +putObject(); + |
This example uploads an object to bucket examplebucket using a file stream.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getFileStream() { + const fs = require('fs'); + // Enter the complete local path of the file to be uploaded. + // If no local path is specified, the system uploads the file from the local path of the project that the sample program belongs to by default. + return fs.createReadStream('D:\\localpath\\examplefile.txt'); +} + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the file stream. + Body: await getFileStream() + }; + // Upload the object using the file stream. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + } + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +putObject(); + |
This API uploads an object to a bucket.
+ObsClient.putObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Access control list (ACL) that can be pre-defined when an object is created. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +When creating an object, you can use this header to specify the storage class for the object. +Restrictions: +None +Value range: +See Table 3. +Default value: +If this parameter is not specified, the object inherits the storage class of the bucket. + |
+
Body + |
+string | stream.Readable + |
+No + |
+Explanation: +Content of the part to upload, which can be in string or stream.Readable form. +Restrictions: +
Value range: +None +Default value: +None + |
+
SourceFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +
Value range: +None +Default value: +None + |
+
Offset + |
+number + |
+No + |
+Explanation: +Start offset of a part in the source file. +Restrictions: +Offset and SourceFile are used together to specify what data is uploaded from the source file. +Value range: +A non-negative integer smaller than the size of the object to be uploaded, in bytes +Default value: +0 + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the upload progress +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (in seconds). + |
+
ContentMD5 + |
+string + |
+No + |
+Explanation: +Base64-encoded MD5 value of the data to be uploaded. It is used for the OBS server to verify data integrity. +Restrictions: +Base64-encoded, 128-bit MD5 value of the request body. +Value range: +Base64-encoded, 128-bit MD5 value of the request body calculated based on the RFC 1864 standard. +Example: n58IG6hfM7vqI4K0vnWpog== +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +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. + |
+
ContentLength + |
+int64 + |
+No + |
+Explanation: +Size of the object to be uploaded. +Restrictions: +
Value range: +0 GB to 5 GB +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +Currently, only KMS is supported. +Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the current object and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the current object, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the object (calculated from the latest modification time of the object). Expired objects are automatically deleted. +Restrictions: +
Value range: +1 to (263 - 1), in days +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
StorageClass + |
++ | +Explanation: +Object storage class. +Value range: +
|
+
VersionId + |
+string + |
+Explanation: +Object version. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
File-based upload uses local files as data sources. This example uploads a file 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object. example/objectname is used in this example. + Key: "example/objectname", + // localfile indicates the path of the local file to be uploaded, which must include the file name. + SourceFile : 'localfile' + }; + // Upload the file. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +putObject(); + |
This API uploads a folder object to a bucket to make it easy to manage data stored in the bucket.
+ObsClient.putObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Access control list (ACL) that can be pre-defined when an object is created. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +When creating an object, you can use this header to specify the storage class for the object. +Restrictions: +None +Value range: +See Table 3. +Default value: +If this parameter is not specified, the object inherits the storage class of the bucket. + |
+
Body + |
+string | stream.Readable + |
+No + |
+Explanation: +Content of the part to upload, which can be in string or stream.Readable form. +Restrictions: +
Value range: +None +Default value: +None + |
+
SourceFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +
Value range: +None +Default value: +None + |
+
Offset + |
+number + |
+No + |
+Explanation: +Start offset of a part in the source file. +Restrictions: +Offset and SourceFile are used together to specify what data is uploaded from the source file. +Value range: +A non-negative integer smaller than the size of the object to be uploaded, in bytes +Default value: +0 + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the upload progress +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (in seconds). + |
+
ContentMD5 + |
+string + |
+No + |
+Explanation: +Base64-encoded MD5 value of the data to be uploaded. It is used for the OBS server to verify data integrity. +Restrictions: +Base64-encoded, 128-bit MD5 value of the request body. +Value range: +Base64-encoded, 128-bit MD5 value of the request body calculated based on the RFC 1864 standard. +Example: n58IG6hfM7vqI4K0vnWpog== +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +If you do not specify this parameter 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 this parameter. + |
+
ContentLength + |
+int64 + |
+No + |
+Explanation: +Size of the object to be uploaded. +Restrictions: +
Value range: +0 GB to 5 GB +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +Currently, only KMS is supported. +Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the current object and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the current object, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the object (calculated from the latest modification time of the object). Expired objects are automatically deleted. +Restrictions: +
Value range: +1 to (263 - 1), in days +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
StorageClass + |
++ | +Explanation: +Object storage class. +Value range: +
|
+
VersionId + |
+string + |
+Explanation: +Object version. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
All elements stored in OBS buckets are called objects. A folder in OBS is essentially an object with a size of 0 and a name ending with a slash (/). You can perform download, delete, or other operations on folder objects just like on regular objects. This example creates a folder object named parent_directory.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify a folder (parent_directory in this example). + Key: "parent_directory/", + }; + // Create a folder object. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +putObject(); + |
Object metadata contains a set of name-value pairs that are used for describing and managing objects.
+Currently, only the system-defined metadata is supported. System-defined metadata consists of system-controlled metadata and user-controlled metadata.
+This API sends a HEAD request for obtaining object metadata.
+ObsClient.setObjectMetadata(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
MetadataDirective + |
++ | +Yes + |
+Explanation: +Policy for copying the source object's attributes +Restrictions: +None +Value range: +See Table 7. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version. Example: G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +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. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ContentDisposition + |
+string + |
+No + |
+Explanation: +Content-Disposition header in the response. It specifies the name of an object when it is downloaded. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ContentEncoding + |
+string + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies the content encoding format when an object is downloaded. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ContentLanguage + |
+string + |
+No + |
+Explanation: +Content-Language header in the response. It specifies what language the object content is in when being downloaded. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +Content-Type header in the response. It specifies the file type of an object when it is downloaded. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +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. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +Storage class of the object. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
MetadataDirective + |
++ | +Explanation: +Policy for copying the source object's attributes +Value range: +See Table 7. + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response. It specifies the name of an object when it is downloaded. + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response. It specifies how the object is encoded when being downloaded. + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response. It specifies what language the object content is in when being downloaded. + |
+
ContentType + |
+string + |
+Explanation: +Content-Type header in the response. It specifies the file type of an object when it is downloaded. + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. + |
+
WebsiteRedirectLocation + |
+string + |
+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 object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
|
+
StorageClass + |
++ | +Explanation: +Storage class configured when copying the object. If this parameter is not specified, the object inherits the storage class of the bucket. +Value range: +See Table 8. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
|
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.CopyMetadata + |
+COPY + |
+When copying an object, the object's attributes are also copied. + NOTICE:
+This value is used only in the API for Copying an Object. + |
+
ObsClient.enums.ReplaceMetadata + |
+REPLACE + |
+REPLACE uses the complete header carried in the current request to replace the original one and deletes the metadata that is not specified. + |
+
ObsClient.enums.ReplaceNewMetadata + |
+REPLACE_NEW + |
+REPLACE_NEW replaces the metadata that already has a value, assigns a value to the metadata that does not have a value, and retains the metadata that is not specified. + NOTICE:
+This value is used only in the API for Configuring Object Metadata. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
This example configures metadata for object example/objectname in bucket examplebucket. The MIME type of the object is set to image/jpeg, the storage class is set to Cold, and custom metadata is also configured for the 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setObjectMetadata() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify a MIME type (image/jpeg in this example) for the object. + ContentType: "image/jpeg", + // Specify a storage class (obsClient.enums.StorageClassCold in this example) for the object. + StorageClass: obsClient.enums.StorageClassCold, + // Specify custom metadata. + Metadata: { "property1": "property-value1", "property2": "property-value2" } + }; + // Configure the metadata for the object. + const result = await obsClient.setObjectMetadata(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set Object(%s)'s metadata successful with bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setObjectMetadata(); + |
When uploading an object or initiating a multipart upload, you can set an expiration time for the object using Expires. This method only supports setting the object expiration time in days, and the expired objects will be automatically deleted by OBS, with a higher priority than bucket lifecycle rules.
+When uploading an object, you can specify when it expires after being created.
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function putObject() {
+ try {
+ const params = {
+ // Specify the bucket name.
+ Bucket: "examplebucket",
+ // Specify an object (example/objectname in this example).
+ Key: "example/objectname",
+ // localfile indicates the path of the local file to be uploaded, which must include the file name.
+ SourceFile : 'localfile',
+ // Specify how many days can pass before the object expires (30 in this example).
+ Expires : 30
+ };
+ // Upload a file.
+ const result = await obsClient.putObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Put bucket(%s) successful!", params.Bucket);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+putObject()
+When initiating a multipart upload, you can specify when the object expires after it is created.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function initiateMultipartUpload() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object (example/objectname in this example). + Key: "example/objectname", + // Specify how many days can pass before the object expires (30 in this example). + Expires : 30 + }; + // Initiate the multipart upload. + const result = await obsClient.initiateMultipartUpload(params); + if (result.CommonMsg.Status <= 300) { + console.log("Initiate multipart upload successfully with bucket(%s) and object(%s)!", params.Bucket, params.Key); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("UploadId: %s", result.InterfaceResult.UploadId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +initiateMultipartUpload(); + |
This API uploads a file or folder to an existing OBS bucket. You can upload text, pictures, videos, or any other types of files.
+This API adds data to the end of a specified object. If there is no object with the same key found in the bucket, a new object is created.
+The latest modification time of the object is updated each time an upload is appended.
+ObsClient.appendObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
Position + |
+number + |
+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. For the second append upload, the value of position should be set to the value of NextAppendPosition returned in the response when the first upload is successful. +Value range: +0 to (263 – 1), in bytes +Default value: +0 + |
+
Body + |
+string | stream.Readable + |
+No + |
+Explanation: +Content of the part to upload, which can be in string or stream.Readable form. +Restrictions: +
Value range: +None +Default value: +None + |
+
SourceFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +
Value range: +None +Default value: +None + |
+
Offset + |
+number + |
+No + |
+Explanation: +Start offset of a part in the source file. +Restrictions: +Offset and SourceFile are used together to specify what data is uploaded from the source file. +Value range: +A non-negative integer smaller than the size of the object to be uploaded, in bytes +Default value: +0 + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the upload progress + NOTE:
+This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (in seconds). +Restrictions: +None +Value range: +None +Default value: +None + |
+
ContentMD5 + |
+string + |
+No + |
+Explanation: +Base64-encoded MD5 value of the data to be uploaded. It is used for the OBS server to verify data integrity. +Restrictions: +Base64-encoded, 128-bit MD5 value of the request body. +Value range: +Base64-encoded, 128-bit MD5 value of the request body calculated based on the RFC 1864 standard. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Access control list (ACL) that can be pre-defined when an object is created. +Restrictions: +This parameter can only be configured in the first request for append upload. The configurations specified in the first request will be used in subsequent requests by default. +Value range: +See Table 2. +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +This parameter can only be configured in the first request for append upload. The configurations specified in the first request will be used in subsequent requests by default. +Value range: +See What Is Content-Type (MIME)? +Default value: +If you do not specify this parameter 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 this parameter. + |
+
ContentLength + |
+int64 + |
+No + |
+Explanation: +Size of the object to be uploaded. +Restrictions: +
Value range: +0 GB to 5 GB +Default value: +If this parameter is not specified, the SDK automatically calculates the size of the object. + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +
Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +This parameter can only be configured in the first request for append upload. The configurations specified in the first request will be used in subsequent requests by default. +Value range: +Valid value formats are as follows: +
In the preceding formats: +
Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +
Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +
Value range: +None +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +When creating an object, you can use this header to specify the storage class for the object. +Restrictions: +None +Value range: +See Table 3. +Default value: +If this parameter is not specified, the object inherits the storage class of the bucket. + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the current object and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the current object, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the object (calculated from the latest modification time of the object). Expired objects are automatically deleted. +Restrictions: +
Value range: +1 to (263 - 1), in days +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
VersionId + |
+string + |
+Explanation: +Object version. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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. + |
+
NextAppendPosition + |
+int64 + |
+Explanation: +Position from which the next append upload starts +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. For the second append upload, the value of position should be set to the value of NextAppendPosition returned in the response when the first upload is successful. You can also call ObsClient.getObjectMetadata to obtain the value of NextAppendPosition. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
You can call ObsClient.appendObject to upload an object and append content to it. This example uses object example/objectname and 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function appendObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example). + Key: "example/objectname", + // Specify the position where content is appended. For the first upload, set Position to 0. For the subsequent appends, specify the actual position. + Position: 0, + // Specify the data stream of the object to upload. + Body: strings.NewReader("Hello OBS"), + }; + // Upload the object using the append method. + const result = await obsClient.appendObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Append object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("ETag: %s, NextAppendPosition:%d", result.InterfaceResult.ETag, result.InterfaceResult.NextAppendPosition); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +appendObject(); + |
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.
+Uploading large files often fails due to poor network conditions or program breakdowns. It is a waste of resources to restart the upload process upon an upload failure, and the restarted upload process may still suffer from the unstable network. To resolve such issues, you can use the API for resumable upload, whose working principle is to divide the to-be-uploaded file into multiple parts and upload them separately. The upload result of each part is recorded in a checkpoint file in real time. Only when all parts are successfully uploaded, the result indicating a successful upload will be returned. Otherwise, an error is returned in callback function to remind you of calling the API again for re-uploading. Based on the upload status of each part recorded in the checkpoint file, the re-uploading will upload the parts failed to be uploaded previously, instead of uploading all parts. By virtue of this, resources are saved and efficiency is improved.
+The resumable upload interface helps save resources and improve efficiency by restarting an upload from the point of failure and concurrently uploading parts. You do not need to worry about internal service details, such as the creation and deletion of checkpoint files, division of objects, or concurrent uploads of parts.
+The total size of files uploaded by the resumable upload API must be larger than 100 KB.
+ObsClient.uploadFile(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
UploadFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +None +Value range: +None +Default value: +None + |
+
PartSize + |
+number + |
+No + |
+Explanation: +Size of the current part. +Restrictions: +None +Value range: +The value ranges from 100 KB to 5 GB, in bytes. +Default value: +102400 + |
+
TaskNum + |
+number + |
+No + |
+Explanation: +Maximum number of parts that can be uploaded concurrently +Restrictions: +None +Value range: +1~10000 +Default value: +1, indicating concurrent uploads are not used + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the upload progress + NOTE:
+This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (in seconds). +Restrictions: +None +Value range: +None +Default value: +None + |
+
ResumeCallback + |
+function + |
+No + |
+Explanation: +Callback function used to obtain the control parameter for canceling a resumable download +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+
|
+
EnableCheckpoint + |
+boolean + |
+No + |
+Explanation: +Whether to enable the resumable mode. +Restrictions: +None +Value range: +
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 progress. +Restrictions: +This parameter is valid only in the resumable mode. +Value range: +None +Default value: +If this parameter is left blank, the checkpoint file will be in the same directory as the local file to be uploaded. + |
+
EnableCheckSum + |
+boolean + |
+No + |
+Explanation: +Whether to verify the file to upload. If this function is enabled, before each task restarts, the system verifies whether the file to upload is the one used during task initialization. +Restrictions: +This parameter is valid only in the resumable mode. +Value range: +
Default value: +false + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +If you do not specify this parameter 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 this parameter. + |
+
ACL + |
++ | +No + |
+Explanation: +Access control list (ACL) that can be pre-defined when an object is created. +Restrictions: +None +Value range: +See Table 2. +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an assembled object calculated based on the ETag of each part. The ETag is a unique identifier for the object's contents, used to determine if the object has been updated. For example, if the ETag value is A when an object is uploaded and B when the object is downloaded, this indicates the contents of the object have been changed. The ETag reflects changes to an object's contents, 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. + |
+
Bucket + |
+string + |
+Explanation: +Name of the bucket in which parts are assembled + |
+
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
Location + |
+string + |
+Explanation: +URL of the object obtained from assembling the parts. + |
+
VersionId + |
+string + |
+Explanation: +Version ID of the object obtained from assembling the parts. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
This example uploads example/objectname to examplebucket using resumable 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function uploadFile() { + try { + const params = { + // Specify the bucket name. + Bucket: 'examplebucket', + // Specify the object to be created (example/objectname in this example). + Key: 'example/objectname', + //Specify the local file to upload (/tmp/objectname in this example). + UploadFile: 'localfile', + // Specify whether to enable resumable transmission. Value true is used in this example. The default value is false. + EnableCheckpoint: true, + // Specify a part size, in bytes. This example sets each part to 9 MB. + PartSize: 9 * 1024 * 1024, + // Specify the maximum number of parts that can be concurrently transmitted. 5 is used in this example. + TaskNum: 5 + }; + // Upload the object using resumable upload. + const result = await obsClient.uploadFile(params); + if (result.CommonMsg.Status <= 300) { + console.log("Upload file(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("ETag: %s", result.InterfaceResult.ETag) + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +uploadFile(); + |
Performing a browser-based upload is to upload objects to a specified bucket in HTML form. The maximum size of an object is 5 GB.
+You can call ObsClient.createPostSignatureSync to generate request parameters for a browser-based upload. The procedure is as follows:
+ObsClient.createPostSignatureSync(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
Expires + |
+Number + |
+No + |
+Explanation: +Validity period of authentication for a browser-based upload +Restrictions: +None +Value range: +A positive integer, in seconds +Default value: +300 + |
+
FormParams + |
+Object + |
+No + |
+Explanation: +Parameters used for browser-based uploads, excluding key, policy, and signature. +Restrictions: +None +Value range: +
Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
OriginPolicy + |
+String + |
+Explanation: +policy not encoded using Base64. This parameter can only be used for verification. + |
+
Policy + |
+String + |
+Explanation: +policy in the form. + |
+
Signature + |
+String + |
+Explanation: +signature in the form. + |
+
The following sample code shows how to generate the parameters in a browser-based upload request.
+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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +function createSignedUrlSync() { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object (example/objectname in this example). + Key: "example/objectname", + // Specify the validity period of the signed URL, in seconds (3600 in this example). + Expires: 3600, + // Specify the headers that must be carried in the request. + FormParams: { + 'x-obs-acl': 'public-read', + 'content-type': 'text/plain' + } + }; + // Create a signed URL for uploading an object. + const res = obsClient.createPostSignatureSync(params); + console.log("OriginPolicy : %s", res.OriginPolicy); + console.log("Policy: %s", res.Policy); + console.log("Signature: %v", res.Signature); +}; + +createSignedUrlSync() + |
Code of an HTML form example is as follows:
+<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> +<!-- Base64 code of the policy --> +<input type="hidden" name="policy" value="*** Provide your policy ***" /> +<!-- AK --> +<input type="hidden" name="AccessKeyId" value="*** Provide your access key ***"/> +<!-- Signature information --> +<input type="hidden" name="signature" value="*** Provide your signature ***"/> + +<input name="file" type="file" /> +<input name="submit" value="Upload" type="submit" /> +</form> +</body> +</html>+
OBS Node.js SDK provides abundant APIs for downloading objects in the following modes:
+You can call ObsClient.getObject to download an object.
+This API downloads an object as text from OBS to your local computer.
+ObsClient.getObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID. Example: G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
SaveAsFile + |
+string + |
+No + |
+Explanation: +The download path with the file name contained +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
SaveAsStream + |
+boolean + |
+No + |
+Explanation: +Whether the object is returned as a readable stream +Value range: +
Default value: +false + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). +Restrictions: +None +Value range: +None +Default value: +None + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
Range + |
+string + |
+No + |
+Explanation: +Download range. For example, 0-999 indicates the range is from byte 1 to byte 1000. +Restrictions: +The maximum length of Range is the length of the object minus 1. If the specified value exceeds this limit, the length of the object minus 1 is used. +Value range: +0 to the object length minus 1. Format: bytes=x-y +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain only one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
ResponseCacheControl + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Cache-Control header in the response. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ResponseContentDisposition + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Disposition header in the response. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ResponseContentEncoding + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Encoding header in the response. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ResponseContentLanguage + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Language header in the response. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ResponseContentType + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Type header in the response. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
ResponseExpires + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Expires header in the response. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
ContentLength + |
+string + |
+Explanation: +Object size + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response + |
+
ETag + |
+string + |
+Explanation: +ETag of the object. + |
+
VersionId + |
+string + |
+Explanation: +Object version + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class + |
+
Expiration + |
+string + |
+Explanation: +Expiration details + |
+
Content + |
+string | +stream.Readable + |
+Explanation: +Content of the object. The content is left blank if SaveAsFile was specified. The content is a stream.Readable object if SaveAsStream was set to true. The content is a String object if neither SaveAsFile nor SaveAsStream was specified. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
This example downloads object examplebucket/objectname as text.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + }; + + // Download the object as text. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Object Content: %s', result.InterfaceResult.Content); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
This API downloads an object as a stream from OBS to your local computer.
+ObsClient.getObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
SaveAsFile + |
+string + |
+No + |
+Explanation: +The download path with the file name contained +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
SaveAsStream + |
+boolean + |
+No + |
+Explanation: +Whether the object is returned as a readable stream +Value range: +
Default value: +false + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). +Restrictions: +None +Value range: +None +Default value: +None + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
Range + |
+string + |
+No + |
+Explanation: +Download range. For example, 0-999 indicates the range is from byte 1 to byte 1000. +Restrictions: +The maximum length of Range is the length of the object minus 1. If the specified value exceeds this limit, the length of the object minus 1 is used. +Value range: +0 to the object length minus 1. Format: bytes=x-y +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain only one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
ResponseCacheControl + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Cache-Control header in the response. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ResponseContentDisposition + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Disposition header in the response. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ResponseContentEncoding + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Encoding header in the response. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ResponseContentLanguage + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Language header in the response. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ResponseContentType + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Type header in the response. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
ResponseExpires + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Expires header in the response. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
ContentLength + |
+string + |
+Explanation: +Object size + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object. + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response + |
+
ETag + |
+string + |
+Explanation: +ETag of the object. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class + |
+
Expiration + |
+string + |
+Explanation: +Expiration details + |
+
Content + |
+string | +stream.Readable + |
+Explanation: +Content of the object. The content is left blank if SaveAsFile was specified. The content is a stream.Readable object if SaveAsStream was set to true. The content is a Buffer object if neither SaveAsFile nor SaveAsStream was specified. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
This example downloads object examplebucket/objectname using the stream.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + // Specify that the object is returned as a stream (stream.Readable). + SaveAsStream: true + }; + + // Download the object using the stream. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Object Content:'); + result.InterfaceResult.Content.on('data', (data) => { + console.log(data.toString()); + }); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
This API downloads an object as a file from OBS to your local computer.
+ObsClient.getObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
SaveAsFile + |
+string + |
+No + |
+Explanation: +The download path with the file name contained +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
SaveAsStream + |
+boolean + |
+No + |
+Explanation: +Whether the object is returned as a readable stream +Value range: +
Default value: +false + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). +Restrictions: +None +Value range: +None +Default value: +None + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
Range + |
+string + |
+No + |
+Explanation: +Download range. For example, 0-999 indicates the range is from byte 1 to byte 1000. +Restrictions: +The maximum length of Range is the length of the object minus 1. If the specified value exceeds this limit, the length of the object minus 1 is used. +Value range: +0 to the object length minus 1. Format: bytes=x-y +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain only one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
ResponseCacheControl + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Cache-Control header in the response. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ResponseContentDisposition + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Disposition header in the response. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ResponseContentEncoding + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Encoding header in the response. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ResponseContentLanguage + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Language header in the response. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ResponseContentType + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Type header in the response. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
ResponseExpires + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Expires header in the response. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
ContentLength + |
+string + |
+Explanation: +Object size + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response + |
+
ETag + |
+string + |
+Explanation: +ETag of the object. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class + |
+
Expiration + |
+string + |
+Explanation: +Expiration details + |
+
Content + |
+string | +stream.Readable + |
+Explanation: +Content of the object. The content is left blank if SaveAsFile was specified. The content is a stream.Readable object if SaveAsStream was set to true. The content is a Buffer object if neither SaveAsFile nor SaveAsStream was specified. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
This example downloads object examplebucket/objectname as a file.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + // Specify the destination path for the downloaded object. + SaveAsFile: 'localfile' + }; + + // Download an object as a file. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
This API downloads part of an object from OBS to your local computer. 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 will be returned. This download method can also be used to concurrently download parts of a large object.
+ObsClient.getObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
SaveAsFile + |
+string + |
+No + |
+Explanation: +The download path with the file name contained +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
SaveAsStream + |
+boolean + |
+No + |
+Explanation: +Whether the object is returned as a readable stream +Value range: +
Default value: +false + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). +Restrictions: +None +Value range: +None +Default value: +None + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
Range + |
+string + |
+No + |
+Explanation: +Download range. For example, 0-999 indicates the range is from byte 1 to byte 1000. +Restrictions: +The maximum length of Range is the length of the object minus 1. If the specified value exceeds this limit, the length of the object minus 1 is used. +Value range: +0 to the object length minus 1. Format: bytes=x-y (bytes=1-1000 as an example) +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
ResponseCacheControl + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Cache-Control header in the response. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ResponseContentDisposition + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Disposition header in the response. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ResponseContentEncoding + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Encoding header in the response. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ResponseContentLanguage + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Language header in the response. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ResponseContentType + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Type header in the response. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
ResponseExpires + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Expires header in the response. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
ContentLength + |
+string + |
+Explanation: +Object size + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object. + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response + |
+
ETag + |
+string + |
+Explanation: +ETag of the object. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class + |
+
Expiration + |
+string + |
+Explanation: +Expiration details + |
+
Content + |
+string | +stream.Readable + |
+Explanation: +Content of the object. The content is left blank if SaveAsFile was specified. The content is a stream.Readable object if SaveAsStream was set to true. The content is a Buffer object if neither SaveAsFile nor SaveAsStream was specified. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
This example downloads object examplebucket/objectname from 0 to 1,000 bytes.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + // Specify the download range. + Range: 'bytes=0-1000' + }; + // Download the object based on the range. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Object Content: %s', result.InterfaceResult.Content); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
This API downloads objects that meet specified conditions from OBS to a local computer.
+ObsClient.getObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
SaveAsFile + |
+string + |
+No + |
+Explanation: +The download path with the file name contained +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
SaveAsStream + |
+boolean + |
+No + |
+Explanation: +Whether the object is returned as a readable stream +Value range: +
Default value: +false + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
Range + |
+string + |
+No + |
+Explanation: +Download range. For example, 0-999 indicates the range is from byte 1 to byte 1000. +Restrictions: +The maximum length of Range is the length of the object minus 1. If the specified value exceeds this limit, the length of the object minus 1 is used. +Value range: +0 to the object length minus 1. Format: bytes=x-y +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
ResponseCacheControl + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Cache-Control header in the response. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ResponseContentDisposition + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Disposition header in the response. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ResponseContentEncoding + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Encoding header in the response. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ResponseContentLanguage + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Language header in the response. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ResponseContentType + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Type header in the response. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
ResponseExpires + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Expires header in the response. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
ContentLength + |
+string + |
+Explanation: +Object size + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response + |
+
ETag + |
+string + |
+Explanation: +ETag of the object. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class + |
+
Expiration + |
+string + |
+Explanation: +Expiration details + |
+
Content + |
+string | +stream.Readable + |
+Explanation: +Content of the object. The content is left blank if SaveAsFile was specified. The content is a stream.Readable object if SaveAsStream was set to true. The content is a Buffer object if neither SaveAsFile nor SaveAsStream was specified. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
This example downloads object examplebucket/objectname and specifies that the object can be downloaded only when it has been modified since Wed, 04 Jul 2018 08:54:53 GMT.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + // If modified since the specified time, the object is downloaded. Otherwise, a 304 code without a message body is returned. + IfModifiedSince: 'Wed, 04 Jul 2018 08:54:53 GMT' + }; + // Download the object based on the specified conditions. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Object Content: %s', result.InterfaceResult.Content); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
When downloading an object, you can rewrite some HTTP/HTTPS response headers. The following table lists rewritable response headers.
+ +Parameter + |
+Description + |
+
|---|---|
ResponseContentType + |
+Rewrites Content-Type in HTTP/HTTPS responses. + |
+
ResponseContentLanguage + |
+Rewrites Content-Language in HTTP/HTTPS responses. + |
+
ResponseExpires + |
+Rewrites Expires in HTTP/HTTPS responses. + |
+
ResponseCacheControl + |
+Rewrites Cache-Control in HTTP/HTTPS responses. + |
+
ResponseContentDisposition + |
+Rewrites Content-Disposition in HTTP/HTTPS responses. + |
+
ResponseContentEncoding + |
+Rewrites Content-Encoding in HTTP/HTTPS responses. + |
+
This code example rewrites response headers.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example). + Key: 'example/objectname', + // Rewrite a response header (Content-Type in this example). + ResponseContentType : 'image/jpeg' + }; + + // Rewrite the response header. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + // Obtain the response header that was rewritten. + console.log("ContentType:%s", result.InterfaceResult.ContentType) + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
To prolong the validity period of the Cold data restored, you can repeatedly restore the data, but you will be billed for each restoration. After a second restore, the validity period of Standard object copies will be prolonged, and you need to pay for storing these copies during the prolonged period.
+To download an object in the Cold storage class, you need to restore it first. After an object is restored, a copy of the object is saved in the Standard storage class. By doing so, the object in the Cold storage class and its copy in the Standard storage class co-exist in the bucket. The copy will be automatically deleted once its retention period ends.
+This API restores a Cold object in a specified bucket.
+ObsClient.restoreObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +The object specified in ObsClient.restoreObject must be in the Cold storage class. Otherwise, an error is reported. +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Version ID of the Cold object to restore +Restrictions: +None +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 + |
+number + |
+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: +None +Value range: +The value ranges from 1 to 30, in days. +Default value: +None + |
+
Tier + |
++ | +No + |
+Explanation: +Tier of the restoration speed. You can select a suitable tier based on your needs. +Restrictions: +None +Value range: +See Table 2. +Default value: +Standard + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.RestoreTierExpedited + |
+Expedited + |
+Objects can be quickly restored from Cold storage within 1 to 5 minutes. + |
+
ObsClient.enums.RestoreTierStandard + |
+Standard + |
+Objects can be restored from Cold storage within 3 to 5 hours. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.restoreObject to restore a Cold object. Sample code is as follows:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function downloadColdObject() {
+ // Specify the bucket name.
+ const bucketName = "examplebucket";
+ // Specify the object (example/objectname in this example).
+ const objectKey = "example/objectname";
+ try {
+ // Restore a Cold object.
+ const restoreObjectOutput = await obsClient.restoreObject({
+ Bucket: bucketName,
+ Key: objectKey,
+ // Specify how long the restored object will be retained, in days. The value ranges from 1 to 30 (1 this example).
+ Days: 1,
+ // Specify the restoration speed (obs.RestoreTierExpedited in this example). By default, the object is restored at an expedited speed.
+ Tier: obs.enums.RestoreTierExpedited
+ });
+ if (restoreObjectOutput.CommonMsg.Status > 300) {
+ handleMessage(restoreObjectOutput.CommonMsg);
+ return;
+ };
+ // Wait for the object to be restored.
+ await sleep(5 * 60);
+ // Download the object.
+ const getObjectOutput = await obsClient.getObject({
+ Bucket: bucketName,
+ Key: objectKey,
+ });
+ if (getObjectOutput.CommonMsg.Status > 300) {
+ handleMessage(getObjectOutput.CommonMsg);
+ return;
+ };
+ console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ console.log('Object Content: %s', result.InterfaceResult.Content);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+function handleMessage(commonMsg) {
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", commonMsg.Status);
+ console.log("Code: %s", commonMsg.Code);
+ console.log("Message: %s", commonMsg.Message);
+ console.log("RequestId: %s", commonMsg.RequestId);
+};
+
+function sleep() {
+ return new Promise(resolve => {
+ setTimeout(resolve, time * 1000);
+ });
+} ;
+
+downloadColdObject();
+The API for resumable download is an encapsulated and enhanced version of range-based download. Downloading large files often fails due to an unstable network or program breakdown. It is a waste of resources to restart the download process upon a download failure, and the restarted download process may still suffer from the unstable network. To resolve such issues, you can use the API for resumable download, whose working principle is to divide the to-be-downloaded file into multiple parts and download them separately. The download result of each part is recorded in a checkpoint file in real time. Only when all parts are successfully downloaded, the result indicating a successful download will be returned. Otherwise, an error is returned in callback function to remind you of calling the API again for re-downloading. Based on the download status of each part recorded in the checkpoint file, the re-downloading will download the parts failed to be downloaded previously, instead of downloading all parts. By virtue of this, resources are saved and efficiency is improved.
+By resuming a failed download from where it failed, this API helps save resources. In addition, parts can be downloaded concurrently, which helps speed up the download. During the download process, you do not need to take care of internal service details, such as the creation and deletion of checkpoint files, division of objects, or concurrent downloads of parts.
+ObsClient.downloadFile(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
DownloadFile + |
+string + |
+No + |
+Explanation: +The full local path that the object is downloaded to. If this parameter is not specified, the working directory of the current program is used. +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
PartSize + |
+number + |
+No + |
+Explanation: +Size of the current part. +Restrictions: +None +Value range: +The value ranges from 100 KB to 5 GB, in bytes. +Default value: +102400 + |
+
TaskNum + |
+number + |
+No + |
+Explanation: +Maximum number of parts that can be downloaded concurrently +Restrictions: +None +Value range: +1~10000 +Default value: +1, indicating concurrent downloads are not used. + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). +Restrictions: +None +Value range: +None +Default value: +None + |
+
ResumeCallback + |
+function + |
+No + |
+Explanation: +Callback function used to obtain the control parameter for canceling a resumable download +Restrictions: +None +Value range: +None +Default value: +None + NOTE:
+
|
+
EnableCheckpoint + |
+boolean + |
+No + |
+Explanation: +Whether to enable the resumable mode. +Restrictions: +None +Value range: +
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. +Value range: +None +Default value: +If this parameter is left blank, the checkpoint file will be in the same directory as the local path that the file is downloaded to. + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response + |
+
ETag + |
+string + |
+Explanation: +ETag of the object + |
+
VersionId + |
+string + |
+Explanation: +Object version ID + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class + |
+
Expiration + |
+string + |
+Explanation: +Expiration details + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
This example downloads example/objectname from examplebucket using 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function downloadFile() { + try { + const params = { + // Specify the bucket name. + Bucket: 'examplebucket', + // Specify the object (example/objectname in this example). + Key: 'example/objectname', + // Specify a local absolute path (/tmp/objectname in this example) for download. If the path is left blank, the current working directory is used by default. + DownloadFile: 'localfile', + // Specify whether to enable resumable transmission. Value true is used in this example. The default value is false. + EnableCheckpoint: true, + // Specify a part size, in bytes. This example sets each part to 9 MB. + PartSize: 9 * 1024 * 1024, + // Specify the maximum number of parts that can be concurrently transmitted. 5 is used in this example. + TaskNum: 5 + }; + // Download the object using resumable download. + const result = await obsClient.downloadFile(params); + if (result.CommonMsg.Status <= 300) { + console.log("Download file(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("StorageClass:%s, ETag:%s, ContentType:%s, ContentLength:%d, LastModified:%s", + result.InterfaceResult.StorageClass, result.InterfaceResult.ETag, result.InterfaceResult.ContentType, + result.InterfaceResult.ContentLength, result.InterfaceResult.LastModified, + ); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +downloadFile(); + |
Object metadata contains a set of name-value pairs that are used for describing and managing objects.
+Currently, only the system-defined metadata is supported. System-defined metadata consists of 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 for obtaining object metadata.
+ObsClient.getObjectMetadata(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + + |
+
StorageClass + |
++ | +Explanation: +Storage class configured when copying the object. If you do not specify this parameter, the object inherits the storage class of the bucket. +Value range: +See Table 6. + |
+
AllowOrigin + |
+string + |
+Explanation: +If Origin in the request meets the CORS rules of the bucket, AllowedOrigin specified in the CORS rules is returned. AllowedOrigin indicates the origin from which requests can access the bucket. +Restrictions: +Domain name of the origin. Each origin can contain at most one wildcard character (*). Example: https://*.vbs.example.com +Default value: +None + |
+
AllowHeader + |
+string + |
+Explanation: +If RequestHeader in the request meets the CORS rules of the bucket, AllowedHeader specified in the CORS rules is returned. AllowedHeader indicates the allowed headers for cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Default value: +None + |
+
AllowMethod + |
+string + |
+Explanation: +AllowedMethod in the CORS rules of the bucket. It specifies the HTTP method allowed for cross-origin requests, that is, the operation type of buckets and objects. +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
ExposeHeader + |
+string + |
+Explanation: +ExposeHeader in the CORS rules of the bucket. It specifies 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 a list of the allowed additional headers. +Restrictions: +Spaces, asterisks (*), ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Default value: +None + |
+
MaxAgeSeconds + |
+number + |
+Explanation: +MaxAgeSeconds in the CORS rules of the bucket. It specifies the time your client can cache the response for a cross-origin request. +Restrictions: +Each CORS rule can contain at most one MaxAgeSeconds. +Value range: +0 to (231 – 1), in seconds +Default value: +100 + |
+
ContentLength + |
+number + |
+Explanation: +Object size +Value range: +0 to (263 – 1), in bytes +Default value: +None + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object. 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 you do not specify this parameter 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 this parameter. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. +Restrictions: +The time must be in the ISO8601 format, for example, 2018-01-01T00:00:00.000Z. +Default value: +None + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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 + |
+
VersionId + |
+string + |
+Explanation: +Object version ID. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Restore + |
+string + |
+Explanation: +Restoration status of an object. For a Cold object that is being restored or has been restored, this header is returned. +For example, ongoing-request="true" indicates that the object is being restored. ongoing-request="false", expiry-date="Wed, 7 Nov 2012 00:00:00 GMT" indicates that the object has been restored, where expiry-date indicates when the restored object expires. +Restrictions: +If the object is not in the Cold storage class, this parameter is left blank. +Default value: +None + |
+
Expiration + |
+string + |
+Explanation: +Expiration details, for example, "expiry-date=\"Mon, 11 Sep 2023 00:00:00 GMT\"" +Default value: +None + |
+
WebsiteRedirectLocation + |
+string + |
+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 object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +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 + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
You can call ObsClient.getObjectMetadata to obtain the metadata of an object, including its length, MIME type, and custom metadata. The following code shows how to obtain the metadata of object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObjectMetadata() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example). + Key: 'example/objectname', + }; + // Obtain the object metadata. + const result = await obsClient.getObjectMetadata(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("StorageClass:%s, ETag:%s, ContentType:%s, ContentLength:%d, LastModified:%s\n", + result.InterfaceResult.StorageClass, result.InterfaceResult.ETag, result.InterfaceResult.ContentType, + result.InterfaceResult.ContentLength, result.InterfaceResult.LastModified); + // Obtain the custom metadata of the object. + console.log("Metadata:%v", result.InterfaceResult.Metadata); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObjectMetadata(); + |
Object metadata contains a set of name-value pairs that are used for describing and managing objects.
+Currently, system-defined and custom metadata are supported.
+System-defined metadata consists of 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 adds, modifies, or deletes metadata of objects in a bucket.
+ObsClient.setObjectMetadata(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
MetadataDirective + |
++ | +Yes + |
+Explanation: +Policy for copying the source object's attributes +Restrictions: +None +Value range: +See Table 7. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +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. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ContentDisposition + |
+string + |
+No + |
+Explanation: +Content-Disposition header in the response. It specifies the name of an object when it is downloaded. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ContentEncoding + |
+string + |
+No + |
+Explanation: +Content-Encoding header in the response. It specifies the content encoding format when an object is downloaded. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ContentLanguage + |
+string + |
+No + |
+Explanation: +Content-Language header in the response. It specifies what language the object content is in when being downloaded. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +Content-Type header in the response. It specifies the file type of an object when it is downloaded. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +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. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +Storage class of the object. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
MetadataDirective + |
++ | +Explanation: +Policy for copying the source object's attributes +Value range: +See Table 7. + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. It specifies the cache behavior of the web page when an object is downloaded. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response It specifies the name of an object when it is downloaded. + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response. It specifies the content encoding format when an object is downloaded. + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response. It specifies what language the object content is in when being downloaded. + |
+
ContentType + |
+string + |
+Explanation: +Content-Type header in the response. It specifies the file type of an object when it is downloaded. + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response. It specifies the cache expiration time of the web page when the object is downloaded. + |
+
WebsiteRedirectLocation + |
+string + |
+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 object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
|
+
StorageClass + |
++ | +Explanation: +Storage class configured when copying the object. If this parameter is not specified, the object inherits the storage class of the bucket. +Value range: +See Table 8. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
|
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.CopyMetadata + |
+COPY + |
+When copying an object, the object's attributes are also copied. + NOTICE:
+This value is used only in the API for Copying an Object. + |
+
ObsClient.enums.ReplaceMetadata + |
+REPLACE + |
+REPLACE uses the complete header carried in the current request to replace the original one and deletes the metadata that is not specified. + |
+
ObsClient.enums.ReplaceNewMetadata + |
+REPLACE_NEW + |
+REPLACE_NEW replaces the metadata that already has a value, assigns a value to the metadata that does not have a value, and retains the metadata that is not specified. + NOTICE:
+This value is used only in the API for Configuring Object Metadata. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
This example configures metadata for object example/objectname in bucket examplebucket. The MIME type of the object is set to image/jpeg, the storage class is set to Cold, and custom metadata is also configured for the 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setObjectMetadata() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify a MIME type (image/jpeg in this example) for the object. + ContentType: "image/jpeg", + // Specify a storage class (obsClient.enums.StorageClassCold in this example) for the object. + StorageClass: obsClient.enums.StorageClassCold, + // Specify custom metadata. + Metadata: { "property1": "property-value1", "property2": "property-value2" } + }; + // Configure the metadata for the object. + const result = await obsClient.setObjectMetadata(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set Object(%s)'s metadata successful with bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setObjectMetadata(); + |
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 an object.
+ObsClient.getObjectAcl(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
VersionId + |
+string + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A + |
+
Owner + |
++ | +Explanation: +Object owner. For details, see Owner. + |
+
Delivered + |
+string + |
+Explanation: +Whether the bucket ACL is applied to the objects in the bucket. + |
+
Grants + |
+Grant[] + |
+Explanation: +Grantees' permission information. For details, see Table 7. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Grantee + |
++ | +Yes if used as a request parameter + |
+Explanation: +Grantee information. For details, see Table 8. + |
+
Permission + |
++ | +Yes if used as a request parameter + |
+Explanation: +Granted permission +Value range: +See Table 11. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Type + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Grantee type +Value range: +See Table 9. +Default value: +None + |
+
ID + |
+string + |
+Yes if this parameter is used as a request parameter and Type is set to a user + |
+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 + |
+
Name + |
+string + |
+No if used as a request parameter + |
+Explanation: +Account name of the grantee. +Restrictions: +
Default value: +None + |
+
URI + |
++ | +Yes if this parameter is used as a request parameter and Type is set to a group + |
+Explanation: +Authorized user group +Value range: +See Table 10. +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
Group + |
+Grants permissions to user groups. + |
+
CanonicalUser + |
+Grants permissions to individual users. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.GroupAllUsers + |
+AllUsers + |
+All users. + |
+
ObsClient.enums.GroupAuthenticatedUsers + |
+AuthenticatedUsers + |
+Authorized users. This constant is deprecated. + |
+
ObsClient.enums.GroupLogDelivery + |
+LogDelivery + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.PermissionRead + |
+READ + |
+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. + |
+
ObsClient.enums.PermissionWrite + |
+WRITE + |
+A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not applicable to objects. + |
+
ObsClient.enums.PermissionReadAcp + |
+READ_ACP + |
+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. + |
+
ObsClient.enums.PermissionWriteAcp + |
+WRITE_ACP + |
+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. + |
+
ObsClient.enums.PermissionFullControl + |
+FULL_CONTROL + |
+A grantee with this permission for a bucket has PermissionRead, PermissionWrite, PermissionReadAcp, and PermissionWriteAcp permissions for the bucket. +A grantee with this permission for an object has PermissionRead, PermissionReadAcp, and PermissionWriteAcp permissions for the object. + |
+
This example returns the ACL of object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObjectAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example). + Key: 'example/objectname', + }; + // Obtain the object ACL. + const result = await obsClient.getObjectAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s)'s acl successful with bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Owner[ID]: %s', result.InterfaceResult.Owner.ID); + console.log('Owner[Name]: %s', result.InterfaceResult.Owner.Name); + for (let i = 0; i < result.InterfaceResult.Grants.length; i++) { + const grant = result.InterfaceResult.Grants[i]; + fmt.Printf("Grant[%d]-Type:%s, ID:%s, URI:%s, Permission:%s\n", + index, grant.Grantee.Type, grant.Grantee.ID, grant.Grantee.URI, grant.Permission) + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObjectAcl(); + |
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.
+ +An object ACL can be configured in any of the following ways:
+ObsClient.setObjectAcl(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +Pre-defined ACL +Restrictions: +You must specify either ACL or the combination of Owner and Grants. +Value range: +See Table 2. +Default value: +None + |
+
Owner + |
++ | +No + |
+Explanation: +Bucket owner +Restrictions: +
Value range: +See Table 3. +Default value: +None + |
+
Delivered + |
+boolean + |
+No + |
+Explanation: +Whether the ACL of the bucket applies to its objects +Value range: +
Default value: +None + |
+
Grants + |
+Grant[] + |
+No + |
+Explanation: +Grantees and permissions +Restrictions: +
Value range: +See Table 4. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Grantee + |
++ | +Yes if used as a request parameter + |
+Explanation: +Grantee information. For details, see Table 5. + |
+
Permission + |
++ | +Yes if used as a request parameter + |
+Explanation: +Granted permission +Value range: +See Table 8. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Type + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Grantee type +Value range: +See Table 6. +Default value: +None + |
+
ID + |
+string + |
+Yes if this parameter is used as a request parameter and Type is set to a user + |
+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 + |
+
Name + |
+string + |
+No if used as a request parameter + |
+Explanation: +Account name of the grantee. +Restrictions: +
Default value: +None + |
+
URI + |
++ | +Yes if this parameter is used as a request parameter and Type is set to a group + |
+Explanation: +Authorized user group +Value range: +See Table 7. +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
Group + |
+Grants permissions to user groups. + |
+
CanonicalUser + |
+Grants permissions to individual users. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.GroupAllUsers + |
+AllUsers + |
+All users. + |
+
ObsClient.enums.GroupAuthenticatedUsers + |
+AuthenticatedUsers + |
+Authorized users. This constant is deprecated. + |
+
ObsClient.enums.GroupLogDelivery + |
+LogDelivery + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.PermissionRead + |
+READ + |
+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. + |
+
ObsClient.enums.PermissionWrite + |
+WRITE + |
+A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not applicable to objects. + |
+
ObsClient.enums.PermissionReadAcp + |
+READ_ACP + |
+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. + |
+
ObsClient.enums.PermissionWriteAcp + |
+WRITE_ACP + |
+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. + |
+
ObsClient.enums.PermissionFullControl + |
+FULL_CONTROL + |
+A grantee with this permission for a bucket has PermissionRead, PermissionWrite, PermissionReadAcp, and PermissionWriteAcp permissions for the bucket. +A grantee with this permission for an object has PermissionRead, PermissionReadAcp, and PermissionWriteAcp permissions for the object. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 10. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 11. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 12. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an ObsClient instance.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function putObject() {
+ try {
+ const params = {
+ // Specify the bucket name.
+ Bucket: "examplebucket",
+ // Specify the object. example/objectname is used in this example.
+ Key: "example/objectname",
+ // Specify a text object.
+ Body : 'Hello OBS',
+ // Set the object ACL to public read.
+ ACL : obsClient.enums.AclPublicRead
+ };
+ // Upload the object.
+ const result = await obsClient.putObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Put object(%s) under the bucket(%s) successful!!", params.Key, params.Bucket);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ console.log("StorageClass:%s, ETag:%s", result.InterfaceResult.StorageClass, result.InterfaceResult.ETag);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+putObject();
+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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setObjectAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Set the object ACL to private read and write. + ACL : obsClient.enums.AclPrivate + }; + // Set the object ACL. + const result = await obsClient.setObjectAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set Object(%s)'s acl successful with Bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setObjectAcl(); + |
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setObjectAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the version ID of the object. + VersionId: 'G001117FCE89978B0000401205D5DC9A', + // Specify the owner of the object. + Owner: { 'ID': 'ownerid' }, +// Specify the information about the authorized user. + Grants: [ + // Grant the write permission to a specified user (0a03f5833900d3730f13c00f49d5exxx in this example). + { Grantee: { Type: 'CanonicalUser', ID: '0a03f5833900d3730f13c00f49d5exxx' }, Permission: obsClient.enums.PermissionWrite }, + // Grant the read permission to all users. + { Grantee: { Type: 'Group', URI: obsClient.enums.GroupAllUsers }, Permission: obsClient.enums.PermissionRead }, + ] + }; + // Set the ACL. + const result = await obsClient.setObjectAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set Object(%s)'s acl successful with Bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setObjectAcl(); + |
This API lists some or all of the objects in a bucket. You can configure the prefix, number, or start position as the filter to list objects. Returned objects are listed in alphabetical order by object name.
+ObsClient.listObjects(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Marker + |
+string + |
+No + |
+Explanation: +Object name to start with when listing objects in a bucket. Objects after the specified object are returned in alphabetical order. +Restrictions: +This parameter is only used for listing objects with a single version. +Value range: +The value can contain 1 to 1,024 characters. +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. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
MaxKeys + |
+number + |
+No + |
+Explanation: +The maximum number of objects returned in the response in alphabetical order +Restrictions: +None +Value range: +The value ranges from 1 to 1000. If the specified value is greater than 1000, 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, 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 placed separately into another CommonPrefixes with bbcd as the prefix. +For a parallel file system, if this parameter is not specified, all the content in the directory is recursively listed by default, and subdirectories are also listed. In big data scenarios, parallel file systems usually have multiple directory levels, and each directory level has a large number of objects. In such case, you are advised to configure [delimiter=/] to list only the content in the current directory, without the content in subdirectories, to make the listing more efficient. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Location + |
+string + |
+Explanation: +Region where a bucket is located. + |
+
Bucket + |
+string + |
+Explanation: +Bucket name + |
+
Prefix + |
+string + |
+Explanation: +Object name prefix, 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, 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. + |
+
Marker + |
+string + |
+Explanation: +Object name to start with when listing objects. Objects after the specified object are returned in alphabetical order. + |
+
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, 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 placed separately into another CommonPrefixes with bbcd as the prefix. +For a parallel file system, if this parameter is not specified, all the content in the directory is recursively listed by default, and subdirectories are also listed. In big data scenarios, parallel file systems usually have multiple directory levels, and each directory level has a large number of objects. In such case, you are advised to configure [delimiter=/] to list only the content in the current directory, without the content in subdirectories, to make the listing more efficient. + |
+
MaxKeys + |
+number + |
+Explanation: +The maximum number of objects returned in the response in alphabetical order. This parameter corresponds to the same parameter in the request. + |
+
IsTruncated + |
+string + |
+Explanation: +Whether all results 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: +
|
+
NextMarker + |
+string + |
+Explanation: +Where in the bucket the next listing begins. If not all results are returned, the response contains this parameter to mark the last object listed in the request. In a subsequent request, you can set Marker to the value of this parameter to list the remaining objects. + |
+
Contents + |
+Content[] + |
+Explanation: +List of objects in the bucket. For details, see Content. + |
+
CommonPrefixes + |
++ | +Explanation: +List of object name prefixes grouped based on the Delimiter parameter (if specified) +Value range: +See Table 7. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified, in UTC. + |
+
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 B when the object is downloaded, this indicates the contents of the object have been changed. The ETag reflects changes to an object's contents, not its metadata. Objects created by the upload and copy operations are assigned 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. + |
+
Size + |
+number + |
+Explanation: +Object size, in bytes. + |
+
Owner + |
++ | +Explanation: +Object owner. The value contains the domain ID and name of the object owner. For details, see Table 8. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. + |
+
Type + |
+string + |
+Explanation: +Type of the object +Value range: +
|
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Prefix + + |
+string + |
+Explanation: +Prefix of objects in a bucket +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
The following sample code shows how to list objects in simple mode. 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // List objects in a bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + access_key_id: process.env.ACCESS_KEY_ID, + // Obtain an AK/SK pair on the management console. + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + }; + // List objects in a bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object prefix (test/ in this example). Objects whose names contain the specified prefix will be listed. + Prefix: "test/", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + }; + + // List objects in a bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object prefix (test/ in this example). Objects whose names contain the specified prefix will be listed. + Prefix: "test/", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + // Specify the position (test/test2 in this example) where the object listing starts. + Marker: "test/test2", + }; + // List objects in a bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an encoding type. url is used in this example. If the objects to list contain special characters, this parameter must be passed. + EncodingType: "url", + }; + while (true) { + // List object versions in the bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status > 300) { + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + if (result.InterfaceResult.IsTruncated === "true") { + params.KeyMarker = result.InterfaceResult.NextKeyMarker; + } else { + break; + }; + }; + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
OBS does not involve folders like in a file system. All elements in buckets are objects. Folders are actually objects whose sizes are 0 and whose names end with a slash (/). When you set a folder name as the prefix, objects in this folder will be listed. Sample code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object prefix (test/ in this example). Objects whose names contain the specified prefix will be listed. + Prefix: "test/", + // Specify an encoding type. url is used in this example. If the objects to list contain special characters, this parameter must be passed. + EncodingType: "url", + }; + let count = 1 + while (true) { + // List object versions in the bucket. + const result = await obsClient.listObjects(params); + if (result.CommonMsg.Status > 300) { + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + const val = result.InterfaceResult.Contents[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, LastModified:%s, Size:%d', + count++, val.Owner.ID, val.ETag, val.Key, val.LastModified, val.Size); + }; + if (result.InterfaceResult.IsTruncated === "true") { + params.Marker = result.InterfaceResult.NextMarker; + } else { + break; + }; + }; + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listObjects(); + |
Exercise caution when performing this operation. If the versioning function is disabled for the bucket where the object is located, the object cannot be restored after being deleted.
+This API deletes an object in the specified bucket to save space and costs.
+ObsClient.deleteObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
DeleteMarker + |
+boolean + |
+Explanation: +Whether the deleted object is a delete marker. +Value range: +
|
+
VersionId + |
+string + |
+Explanation: +ID of the object version to be deleted, for example, G001117FCE89978B0000401205D5DC9 + |
+
This example deletes object example/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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example) to delete. + Key: 'example/objectname', + }; + // Delete the object. + const result = await obsClient.deleteObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteObject(); + |
Exercise caution when performing this operation. If versioning is disabled for the bucket where objects are located, objects cannot be restored after being deleted.
+This API deletes objects in a batch from a specific bucket. Deleted objects cannot be restored.
+In a batch deletion, OBS concurrently deletes the specified objects and returns the deletion result of each object.
+ObsClient.deleteObjects(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Quiet + |
+boolean + |
+No + |
+Explanation: +Mode of the response to the request for deleting objects in a batch +Restrictions: +None +Value range: +
Default value: +false + |
+
Objects + |
++ | +Yes + |
+Explanation: +List of objects to be deleted. For details, see Table 2. +Restrictions: +A maximum of 1000 objects can be deleted at a time. +Value range: +None +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +ID of the object version to be deleted, for example, G001117FCE89978B0000401205D5DC9. +Restrictions: +None +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. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Deleteds + |
+Deleted[] + |
+Explanation: +List of objects that were successfully deleted. For details, see Table 7. + |
+
Errors + |
+Error[] + |
+Explanation: +List of objects that failed to be deleted. For details, see Table 8. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9. + |
+
DeleteMarker + |
+bool + |
+Explanation: +Whether the deleted object is a delete marker. +Value range: +
|
+
DeleteMarkerVersionId + |
+string + |
+Explanation: +Version ID of a delete marker to create or delete. +OBS returns this element in the response when a delete marker is created or deleted for a versioning-enabled bucket. This element will be returned in either of the following cases: +
|
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9. + |
+
Code + |
+string + |
+Explanation: +Error code for the failed deletion. + |
+
Message + |
+string + |
+Explanation: +Error message for the failed deletion. + |
+
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object list to delete. + Objects: [ + { Key: 'objectname1', VersionId: "version1" }, + { Key: 'objectname2', VersionId: "version2" }, + { Key: 'objectname3', VersionId: "version3" } + ] + }; + // Delete the objects in a batch. + const result = await obsClient.deleteObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + // Return details about which objects were deleted. + console.log('Deleteds:'); + for (let i = 0; i < result.InterfaceResult.Deleteds.length; i++) { + const deleted = result.InterfaceResult.Deleteds[i]; + console.log("Deleted[%d]-Key:%s, VersionId:%s", i, deleted.Key, deleted.VersionId); + }; + // Return details about which objects were not deleted. + console.log('Errors:'); + for (let i = 0; i < result.InterfaceResult.Errors.length; i++) { + const err = result.InterfaceResult.Errors[i]; + console.log("Errors[%d]-Key:%s, Code:%s", i, err.Key, err.Code); + }; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteObjects(); + |
This API copies an object stored in OBS to a specified path. You can copy an object of up to 5 GB in a single operation.
+ObsClient.copyObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. + |
+
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. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
CopySource + |
+string + |
+Yes + |
+Explanation: +Names of the source bucket and object. If the source object has multiple versions, the versionId parameter is used to specify the desired version. +Example: source_bucket/sourceObject?versionId=G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Restrictions: +Full-width characters and percent signs (%) must be URL-encoded. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +ACL that can be pre-defined during the object copy. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
MetadataDirective + |
++ | +No + |
+Explanation: +Policy for copying the source object's attributes +Restrictions: +None +Value range: +See Table 3. +Default value: +None + |
+
CopySourceIfMatch + |
+string + |
+No + |
+Explanation: +If the ETag of the source object is the same as the one specified by this parameter, it is copied. Otherwise, an error is returned. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
CopySourceIfNoneMatch + |
+string + |
+No + |
+Explanation: +If the ETag of the source object is different from the one specified by this parameter, it is copied. Otherwise, an error is returned. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
CopySourceIfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the source object has not been modified since the specified time, it is copied. Otherwise, an exception is thrown. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
CopySourceIfModifiedSince + |
+string + |
+No + |
+Explanation: +If the source object has been modified since the specified time, it is copied. Otherwise, an exception is thrown. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
CopySourceSseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
CopySourceSseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
CacheControl + |
+string + |
+No + |
+Explanation: +Cache-Control in the response is rewritten. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ContentDisposition + |
+string + |
+No + |
+Explanation: +Content-Disposition in the response is rewritten. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ContentEncoding + |
+string + |
+No + |
+Explanation: +Content-Encoding in the response is rewritten. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ContentLanguage + |
+string + |
+No + |
+Explanation: +Content-Language in the response is rewritten. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +Content-Type in the response is rewritten. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
Expires + |
+string + |
+No + |
+Explanation: +Expires in the response is rewritten. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +Storage class configured when copying the object. +Restrictions: +None +Value range: +See Table 4. +Default value: +None. If this parameter is not specified, the storage class of the bucket is used as that of the object. + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the target object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the object to copy and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the object to copy. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the object to copy. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the object to copy, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
SuccessActionRedirect + |
+string + |
+No + |
+Explanation: +Address (URL) to which a successfully answered request is redirected. +If the value is valid and the request is successful, OBS returns status code 303. Location contains the value of this parameter, as well as the bucket name, object name, and object ETag. +If the value is invalid, OBS ignores this parameter. In such case, the Location header is the object address, and OBS returns a status code based on whether the operation succeeded or failed. +Restrictions: +None +Value range: +None +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.CopyMetadata + |
+COPY + |
+When copying an object, the object's attributes are also copied. + NOTICE:
+This value is used only in the API for Copying an Object. + |
+
ObsClient.enums.ReplaceMetadata + |
+REPLACE + |
+REPLACE uses the complete header carried in the current request to replace the original one and deletes the metadata that is not specified. + |
+
ObsClient.enums.ReplaceNewMetadata + |
+REPLACE_NEW + |
+REPLACE_NEW replaces the metadata that already has a value, assigns a value to the metadata that does not have a value, and retains the metadata that is not specified. + NOTICE:
+This value is used only in the API for Configuring Object Metadata. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 7. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 8. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
LastModified + |
+string + |
+Explanation: +Time when the target object was last modified, in UTC + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of the target object. The ETag is a unique identifier for the object's contents, used to determine if the object has been updated. For example, if the ETag value is A when an object is uploaded and B when the object is downloaded, this indicates the contents of the object have been changed. The ETag reflects changes to an object's contents, 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. + |
+
CopySourceVersionId + |
+string + |
+Explanation: +Version ID of the source object + |
+
VersionId + |
+string + |
+Explanation: +Version ID of the target object + |
+
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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function copyObject() { + try { + const params = { + // Specify the target bucket name. + Bucket: "examplebucket", + // Specify the name of the object copy (example/objectname in this example). + Key: 'example/objectname', + // Specify the names of the source bucket (sourcebucketname in this example) and source object (sourceobjectkey in this example). + CopySource: 'sourcebucketname/sourceobjectname' + }; + // Copy the source object. + const result = await obsClient.copyObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Copy Object(bucket:%s, object: %s) successful from bucket/object: %s!", params.Bucket, params.Key, params.CopySource); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("ETag: %s, LastModified:%s", result.InterfaceResult.ETag, result.InterfaceResult.LastModified); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +copyObject(); + |
Use the Metadata parameter to specify the object's customized metadata to be rewritten and the MetadataDirective parameter to specify the rewrite mode, which can be ObsClient.enums.ReplaceMetadata (rewrite) or ObsClient.enums.CopyMetadata (copy from the source object).
+The following sample code shows how to rewrite object properties.
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function copyObject() {
+ try {
+ const params = {
+ // Specify the target bucket name.
+ Bucket: "examplebucket",
+ // Specify the name of the object copy (example/objectname in this example).
+ Key: 'example/objectname',
+ // Specify the names of the source bucket (sourcebucketname in this example) and source object (sourceobjectkey in this example).
+ CopySource: 'sourcebucketname/sourceobjectname'
+ // Specify custom metadata.
+ Metadata: {'property':'property-value'},
+ // Specify the policy for copying the metadata of the source object. In this example, ObsClient.enums.ReplaceMetadata is used to rewrite the metadata of the source object.
+ MetadataDirective: ObsClient.enums.ReplaceMetadata
+ };
+ // Copy the object.
+ const result = await obsClient.copyObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Copy Object(bucket:%s, object: %s) successful from bucket/object: %s!", params.Bucket, params.Key, params.CopySource);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ console.log("ETag: %s, LastModified:%s", result.InterfaceResult.ETag, result.InterfaceResult.LastModified);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+copyObject();
+When copying an object, you can specify one or more restriction conditions. If the conditions are met, the object will be copied. Otherwise, an error code will be returned and the copy will fail.
+
Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function copyObject() {
+ try {
+ const params = {
+ // Specify the bucket name.
+ Bucket: "examplebucket",
+ // Specify the name of the object copy (example/objectname in this example).
+ Key: 'example/objectname',
+ // Specify the names of the source bucket (sourcebucketname in this example) and source object (sourceobjectkey in this example).
+ CopySource: 'sourcebucketname/sourceobjectname'
+ // Specify the copy conditions. If the source object has been modified since the specified time, it will be copied.
+ CopySourceIfModifiedSince: 'Thu, 31 Dec 2015 16:00:00 GMT',
+ // Specify the copy conditions. If the ETag of the source object is different from the one specified by this parameter, the source object will be copied.
+ CopySourceIfNoneMatch: 'none-match-etag'
+ };
+ // Copy the object.
+ const result = await obsClient.copyObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Copy Object(bucket:%s, object: %s) successful from bucket/object: %s!", params.Bucket, params.Key, params.CopySource);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ console.log("ETag: %s, LastModified:%s", result.InterfaceResult.ETag, result.InterfaceResult.LastModified);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+copyObject();
+Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function copyObject() {
+ try {
+ const params = {
+ // Specify the bucket name.
+ Bucket: "examplebucket",
+ // Specify the name of the object copy (example/objectname in this example).
+ Key: 'example/objectname',
+ // Specify the names of the source bucket (sourcebucketname in this example) and source object (sourceobjectkey in this example).
+ CopySource: 'sourcebucketname/sourceobjectname'
+ // Rewrite the object ACL to public read during the copy.
+ ACL : obsClient.enums.AclPublicRead
+ };
+ // Copy the object.
+ const result = await obsClient.copyObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Copy Object(bucket:%s, object: %s) successful from bucket/object: %s!", params.Bucket, params.Key, params.CopySource);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ console.log("ETag: %s, LastModified:%s", result.InterfaceResult.ETag, result.InterfaceResult.LastModified);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+copyObject();
+OBS allows you to create a URL whose Query parameters carry authentication information by specifying the AK and SK, HTTP method, and request parameters. You can provide this URL for other users to grant them temporary access. When generating a URL, you need to specify the validity period of the URL to restrict the access duration of visitors.
+To grant other users the temporary permission to perform operations (such as upload), you need to generate a URL for the corresponding request (such as PUT) and provide it for users.
+ObsClient.createSignedUrlSync(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Method + |
++ | +Yes + |
+Explanation: +HTTP method. For details, see Table 2. + |
+
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
SpecialParam + |
++ | +No + |
+Explanation: +Sub-resource to be accessed +Restrictions: +None +Value range: +See Table 3. +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the signed URL. +Restrictions: +None +Value range: +
Default value: +300 + |
+
Headers + |
+object + |
+No + |
+Explanation: +Headers in the request. +Restrictions: +None +Value range: +None +Default value: +None + |
+
QueryParams + |
+object + |
+No + |
+Explanation: +Query parameters in the request. +Restrictions: +None +Value range: +None +Default value: +None + |
+
Constant + |
+Description + |
+
|---|---|
GET + |
+HTTP GET request + |
+
POST + |
+HTTP POST request + |
+
PUT + |
+HTTP PUT request + |
+
DELETE + |
+HTTP DELETE request + |
+
HEAD + |
+HTTP HEAD request + |
+
OPTIONS + |
+HTTP OPTIONS request + |
+
Constant + |
+Applicable API + |
+
|---|---|
storagePolicy + |
+Specify or obtain bucket storage classes. + |
+
quota + |
+Specify or obtain bucket quotas. + |
+
storageinfo + |
+Obtain bucket storage information. + |
+
location + |
+Obtain bucket locations. + |
+
acl + |
+Specify or obtain bucket ACLs or object ACLs. + |
+
policy + |
+Specify, obtain, or delete bucket policies. + |
+
cors + |
+Specify, obtain, or delete bucket CORS configurations. + |
+
versioning + |
+Specify or obtain bucket versioning statuses. + |
+
website + |
+Specify, obtain, or delete bucket website configurations. + |
+
logging + |
+Specify or obtain bucket logging settings. + |
+
lifecycle + |
+Specify, obtain, or delete lifecycle rules of buckets. + |
+
notification + |
+Specify or obtain the notification configurations of buckets. + |
+
tagging + |
+Specify, obtain, or delete bucket tags. + |
+
append + |
+Append data to an object. + |
+
delete + |
+Batch delete objects. + |
+
versions + |
+List object versions in buckets. + |
+
uploads + |
+List or initiate multipart uploads in buckets. + |
+
restore + |
+Restore Cold objects. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
SignedUrl + |
+string + |
+Explanation: +The signed URL that carries the authentication information. + |
+
ActualSignedRequestHeaders + |
+object + |
+Explanation: +Headers that need to be included in the request initiated using the signed URL. + |
+
To access OBS using a temporary URL generated by the OBS Node.js SDK, perform the following steps:
+
If a CORS or signature mismatch error occurs, refer to the following steps to troubleshoot the issue:
+The following code examples use a temporary URL to create a bucket or upload, download, list, or delete objects.
+This example creates a bucket using a temporary URL.
+// Import the OBS library.
+// Use npm to install the client.
+var ObsClient = require('esdk-obs-nodejs');
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+var https = require('https');
+var urlLib = require('url');
+var crypto = require('crypto');
+
+// Create an ObsClient instance.
+var obsClient = new ObsClient({
+ // 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.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ server : 'https://your-endpoint'
+});
+
+let bucketName = 'bucketname';
+let method = 'PUT';
+let res = obsClient.createSignedUrlSync({Method : method, Bucket : bucketName});
+let location = 'your-location';
+let content = `<CreateBucketConfiguration><LocationConstraint>${location}</LocationConstraint></CreateBucketConfiguration>`;
+
+// Make a PUT request to create a bucket.
+var url = urlLib.parse(res.SignedUrl);
+var req = https.request({
+ method : method,
+ host : url.hostname,
+ port : url.port,
+ path : url.path,
+ rejectUnauthorized : false,
+ headers : res.ActualSignedRequestHeaders || {}
+});
+
+
+console.log('Creating bucket using url:' + res.SignedUrl);
+
+req.on('response', (serverback) => {
+ var buffers = [];
+ serverback.on('data', (data) => {
+ buffers.push(data);
+ }).on('end', () => {
+
+ if(serverback.statusCode < 300){
+ console.log('Creating bucket using temporary signature succeed.');
+ }else{
+ console.log('Creating bucket using temporary signature failed!');
+ console.log('status:' + serverback.statusCode);
+ console.log('\n');
+ };
+ buffers = Buffer.concat(buffers);
+ if(buffers.length > 0){
+ console.log(buffers.toString());
+ };
+ console.log('\n');
+ });
+}).on('error',(err) => {
+ console.log('Creating bucket using temporary signature failed!');
+ console.log(err);
+ console.log('\n');
+});
+
+if(content){
+ req.write(content);
+};
+req.end();
+This example uploads an object using a temporary URL.
+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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +function createSignedUrlSync() { + // Specify the HTTP method. PUT is used in this example. + const method = 'PUT'; + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object (example/objectname in this example). + Key: "example/objectname", + // Specify the HTTP method. + Method: method, + // Specify the validity period of the signed URL, in seconds (3600 in this example). + Expires: 3600, + // Specify the headers carried in the request. + Headers: { + "Content-Type": "text/plain", + } + }; + + // Create a signed URL for uploading an object. + const res = obsClient.createSignedUrlSync(params); + console.log("SignedUrl: %s", res.SignedUrl); + console.log("ActualSignedRequestHeaders: %v", res.ActualSignedRequestHeaders); + + let content = 'Hello OBS'; + // Make a PUT request to upload an object. + var url = urlLib.parse(res.SignedUrl); + var req = https.request({ + method: method, + host: url.hostname, + port: url.port, + path: url.path, + rejectUnauthorized: false, + headers: res.ActualSignedRequestHeaders || {} + }); + console.log('Creating object using url:' + res.SignedUrl); + + req.on('response', (serverback) => { + var buffers = []; + serverback.on('data', (data) => { + buffers.push(data); + }).on('end', () => { + if (serverback.statusCode < 300) { + console.log('Creating object using temporary signature succeed.'); + } else { + console.log('Creating object using temporary signature failed!'); + console.log('status:' + serverback.statusCode); + console.log('\n'); + }; + buffers = Buffer.concat(buffers); + if (buffers.length > 0) { + console.log(buffers.toString()); + }; + console.log('\n'); + }); + }).on('error', (err) => { + console.log('Creating object using temporary signature failed!'); + console.log(err); + console.log('\n'); + }); + if (content) { + req.write(content); + }; + req.end(); +}; + +createSignedUrlSync(); + |
This example downloads an object using a temporary URL.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +function createSignedUrlSync() { + // Specify the HTTP method. GET is used in this example. + const method = 'GET'; + + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object (example/objectname in this example). + Key: "example/objectname", + // Specify the HTTP method. + Method: method, + // Specify the validity period of the signed URL, in seconds (3600 in this example). + Expires: 3600, + }; + + // Make a GET request to download an object. + var url = urlLib.parse(res.SignedUrl); + var req = https.request({ + method: method, + host: url.hostname, + port: url.port, + path: url.path, + rejectUnauthorized: false, + headers: res.ActualSignedRequestHeaders || {} + }); + console.log('Creating object using url:' + res.SignedUrl); + + req.on('response', (serverback) => { + var buffers = []; + serverback.on('data', (data) => { + buffers.push(data); + }).on('end', () => { + if (serverback.statusCode < 300) { + console.log('Getting object using temporary signature succeed.'); + } else { + console.log('Getting object using temporary signature failed!'); + console.log('status:' + serverback.statusCode); + console.log('\n'); + }; + buffers = Buffer.concat(buffers); + if (buffers.length > 0) { + console.log(buffers.toString()); + }; + console.log('\n'); + }); + }).on('error', (err) => { + console.log('Getting object using temporary signature failed!'); + console.log(err); + console.log('\n'); + }); + req.end(); +}; + +createSignedUrlSync(); + |
This example lists objects using a temporary URL.
+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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +function createSignedUrlSync() { + // Specify the HTTP method. GET is used in this example. + const method = 'GET'; + + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the HTTP method. + Method: method, + // Specify the validity period of the signed URL, in seconds (3600 in this example). + Expires: 3600, + }; + + // Make a GET request to obtain the object list. + var url = urlLib.parse(res.SignedUrl); + var req = https.request({ + method: method, + host: url.hostname, + port: url.port, + path: url.path, + rejectUnauthorized: false, + headers: res.ActualSignedRequestHeaders || {} + }); + console.log('Listing object using url:' + res.SignedUrl); + + req.on('response', (serverback) => { + var buffers = []; + serverback.on('data', (data) => { + buffers.push(data); + }).on('end', () => { + if (serverback.statusCode < 300) { + console.log('Listing object using temporary signature succeed.'); + } else { + console.log('Listing object using temporary signature failed!'); + console.log('status:' + serverback.statusCode); + console.log('\n'); + }; + buffers = Buffer.concat(buffers); + if (buffers.length > 0) { + console.log(buffers.toString()); + }; + console.log('\n'); + }); + }).on('error', (err) => { + console.log('Listing object using temporary signature failed!'); + console.log(err); + console.log('\n'); + }); + req.end(); +}; + +createSignedUrlSync(); + |
This example deletes an object using a temporary URL.
+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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +function createSignedUrlSync() { + // Specify the HTTP method. DELETE is used in this example. + const method = 'DELETE'; + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object (example/objectname in this example). + Key: "example/objectname", + // Specify the HTTP method. + Method: method, + // Specify the validity period of the signed URL, in seconds (3600 in this example). + Expires: 3600, + }; + + // Make a DELETE request to delete the object. + var url = urlLib.parse(res.SignedUrl); + var req = https.request({ + method: method, + host: url.hostname, + port: url.port, + path: url.path, + rejectUnauthorized: false, + headers: res.ActualSignedRequestHeaders || {} + }); + console.log('Deleting object using url:' + res.SignedUrl); + req.on('response', (serverback) => { + var buffers = []; + serverback.on('data', (data) => { + buffers.push(data); + }).on('end', () => { + if (serverback.statusCode < 300) { + console.log('Deleting object using temporary signature succeed.'); + } else { + console.log('Deleting object using temporary signature failed!'); + console.log('status:' + serverback.statusCode); + console.log('\n'); + }; + buffers = Buffer.concat(buffers); + if (buffers.length > 0) { + console.log(buffers.toString()); + }; + console.log('\n'); + }); + }).on('error', (err) => { + console.log('Deleting object using temporary signature failed!'); + console.log(err); + console.log('\n'); + }); + req.end(); +}; + +createSignedUrlSync(); + |
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 versioning for a bucket.
+ObsClient.setBucketVersioning(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
VersionStatus + |
+string + |
+Yes + |
+Explanation: +Versioning status of the bucket. +Restrictions: +None +Value range: +Versioning status of the bucket. Possible values are: +
Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. +For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example configures versioning 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketVersioning() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify a versioning status (Enabled in this example) for the bucket. + VersionStatus: 'Enabled' + }; + + // Configure versioning for the bucket. + const result = await obsClient.setBucketVersioning(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s versioning status successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketVersioning(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.getBucketVersioning to view the versioning status of a bucket. The following code shows how to view 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketVersioning() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // Obtain the versioning status of the bucket. + const result = await obsClient.getBucketVersioning(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s versioning status successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('VersionStatus: %s', result.InterfaceResult.VersionStatus); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketVersioning(); + |
This API downloads an object version from OBS to your local computer.
+ObsClient.getObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Object version ID, for example, G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
SaveAsFile + |
+string + |
+No + |
+Explanation: +The download path with the file name contained +Restrictions: +A file name must be included in the path, for example, aa/bb.txt. +Value range: +None +Default value: +None + |
+
SaveAsStream + |
+boolean + |
+No + |
+Explanation: +Whether the object is returned as a readable stream +Value range: +
Default value: +false + |
+
ProgressCallback + |
+function + |
+No + |
+Explanation: +Callback function for obtaining the download progress + NOTE:
+This callback function contains the following parameters in sequence: number of downloaded bytes, total bytes, and used time (unit: second). +Restrictions: +None +Value range: +None +Default value: +None + |
+
IfMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfModifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified after the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
IfNoneMatch + |
+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. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
IfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the object was modified before the time specified by this parameter, its content is returned. Otherwise, an error code is returned. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
Range + |
+string + |
+No + |
+Explanation: +Download range. For example, 0-999 indicates the range is from byte 1 to byte 1000. +Restrictions: +The maximum length of Range is the length of the object minus 1. If the specified value exceeds this limit, the length of the object minus 1 is used. +Value range: +0 to the object length minus 1. Format: bytes=x-y +Default value: +None + |
+
Origin + |
+string + |
+No + |
+Explanation: +Origin of the cross-domain request specified in the preflight request. It is usually a domain name. +Restrictions: +Each origin can contain at most one wildcard character (*). +Value range: +None +Default value: +None + |
+
RequestHeader + |
+string + |
+No + |
+Explanation: +HTTP headers that can be used in cross-origin requests. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
ResponseCacheControl + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Cache-Control header in the response. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ResponseContentDisposition + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Disposition header in the response. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ResponseContentEncoding + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Encoding header in the response. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ResponseContentLanguage + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Language header in the response. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ResponseContentType + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Content-Type header in the response. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
ResponseExpires + |
+string + |
+No + |
+Explanation: +This parameter is used to rewrite the Expires header in the response. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for decrypting objects. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for decrypting objects when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
DeleteMarker + |
+string + |
+Explanation: +Whether the deleted object is a delete marker. + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified. + |
+
ContentLength + |
+string + |
+Explanation: +Object size. + |
+
CacheControl + |
+string + |
+Explanation: +Cache-Control header in the response. + |
+
ContentDisposition + |
+string + |
+Explanation: +Content-Disposition header in the response. + |
+
ContentEncoding + |
+string + |
+Explanation: +Content-Encoding header in the response. + |
+
ContentLanguage + |
+string + |
+Explanation: +Content-Language header in the response. + |
+
ContentType + |
+string + |
+Explanation: +MIME type of the object. + |
+
Expires + |
+string + |
+Explanation: +Expires header in the response. + |
+
ETag + |
+string + |
+Explanation: +ETag of the object. + |
+
VersionId + |
+string + |
+Explanation: +Object version ID. + |
+
WebsiteRedirectLocation + |
+string + |
+Explanation: +Location where an object is redirected. It is available when website hosting is configured for a bucket. + |
+
StorageClass + |
+string + |
+Explanation: +Object storage class. If the storage class is Standard, this parameter is left blank. + |
+
Restore + |
+string + |
+Explanation: +Restoration status of the object in the Cold storage class. + |
+
Expiration + |
+string + |
+Explanation: +Expiration details. + |
+
Content + |
+string | +stream.Readable + |
+Explanation: +Content of the object. The content is left blank if SaveAsFile was specified. The content is a stream.Readable object if SaveAsStream was set to true. The content is a Buffer object if neither SaveAsFile nor SaveAsStream was specified. + |
+
Metadata + |
+object + |
+Explanation: +Custom metadata of the object. You need to add in the CORS configurations the additional headers allowed to be carried in the response. For example, you can add the x-amz-meta-property1 header to allow custom metadata property1 to be returned. + |
+
You can call ObsClient.getObject to obtain a version of an object by specifying VersionId. Sample code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object to download (example/objectname in this example). + Key: 'example/objectname', + // Specify the version ID of the object. If the version ID is not specified, the object of the latest version is downloaded by default. + VersionId: 'G001117FCE89978B0000401205D5DC9A' + }; + + // Download a version of an object. + const result = await obsClient.getObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObject(); + |
This API copies an object version in a specified bucket. You can copy an object of up to 5 GB in a single operation.
+ObsClient.copyObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
CopySource + |
+string + |
+Yes + |
+Explanation: +Names of the source bucket and object. If the source object has multiple versions, the versionId parameter is used to specify the desired version. +Example: source_bucket/sourceObject?versionId=G001117FCE89978B0000401205D5DC9A +Restrictions: +None +Restrictions: +Full-width characters and percent signs (%) must be URL-encoded. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +ACL that can be pre-defined during the object copy. +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
MetadataDirective + |
++ | +No + |
+Explanation: +Policy for copying the source object's attributes +Restrictions: +None +Value range: +See Table 3. +Default value: +None + |
+
CopySourceIfMatch + |
+string + |
+No + |
+Explanation: +If the ETag of the source object is the same as the one specified by this parameter, it is copied. Otherwise, an error is returned. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
CopySourceIfNoneMatch + |
+string + |
+No + |
+Explanation: +If the ETag of the source object is different from the one specified by this parameter, it is copied. Otherwise, an error is returned. +Restrictions: +None +Value range: +The value must contain 32 characters. +Default value: +None + |
+
CopySourceIfUnmodifiedSince + |
+string + |
+No + |
+Explanation: +If the source object has not been modified since the specified time, it is copied. Otherwise, an exception is thrown. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +Default value: +None + |
+
CopySourceIfModifiedSince + |
+string + |
+No + |
+Explanation: +If the source object has been modified since the specified time, it is copied. Otherwise, an exception is thrown. +Restrictions: +The value must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt. +Value range: +None +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. +The request is redirected to object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Restrictions: +
Value range: +None +Default value: +None + |
+
CopySourceSseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
CopySourceSseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
CacheControl + |
+string + |
+No + |
+Explanation: +Cache-Control in the response is rewritten. +Restrictions: +None +Value range: +See the Cache-Control values defined in HTTP. +Default value: +None + |
+
ContentDisposition + |
+string + |
+No + |
+Explanation: +Content-Disposition in the response is rewritten. +Restrictions: +None +Value range: +See the Content-Disposition values defined in HTTP. +Default value: +None + |
+
ContentEncoding + |
+string + |
+No + |
+Explanation: +Content-Encoding in the response is rewritten. +Restrictions: +None +Value range: +See the Content-Encoding values defined in HTTP. +Default value: +None + |
+
ContentLanguage + |
+string + |
+No + |
+Explanation: +Content-Language in the response is rewritten. +Restrictions: +None +Value range: +See the Content-Language values defined in HTTP. +Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +Content-Type in the response is rewritten. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +None + |
+
Expires + |
+string + |
+No + |
+Explanation: +Expires in the response is rewritten. +Restrictions: +None +Value range: +See the Expires values defined in HTTP. +Default value: +None + |
+
StorageClass + |
++ | +No + |
+Explanation: +Storage class configured when copying the object. +Restrictions: +None +Value range: +See Table 4. +Default value: +None. If this parameter is not specified, the storage class of the bucket is used as that of the object. + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the target object. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the object to copy and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the object to copy. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the object to copy. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the object to copy, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
SuccessActionRedirect + |
+string + |
+No + |
+Explanation: +Address (URL) to which a successfully answered request is redirected. +If the value is valid and the request is successful, OBS returns status code 303. Location contains the value of this parameter, as well as the bucket name, object name, and object ETag. +If the value is invalid, OBS ignores this parameter. In such case, the Location header is the object address, and OBS returns a status code based on whether the operation succeeded or failed. +Restrictions: +None +Value range: +None +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.CopyMetadata + |
+COPY + |
+When copying an object, the object's attributes are also copied. + NOTICE:
+This value is used only in the API for Copying an Object. + |
+
ObsClient.enums.ReplaceMetadata + |
+REPLACE + |
+REPLACE uses the complete header carried in the current request to replace the original one and deletes the metadata that is not specified. + |
+
ObsClient.enums.ReplaceNewMetadata + |
+REPLACE_NEW + |
+REPLACE_NEW replaces the metadata that already has a value, assigns a value to the metadata that does not have a value, and retains the metadata that is not specified. + NOTICE:
+This value is used only in the API for Configuring Object Metadata. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 7. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 8. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
LastModified + |
+string + |
+Explanation: +Time when the target object was last modified, in UTC. + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of the target object. The ETag is a unique identifier for the object's contents, used to determine if the object has been updated. For example, if the ETag value is A when an object is uploaded and becomes B when the object is downloaded, this indicates the contents of the object were changed. The ETag reflects changes of an object, not of the 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. + |
+
CopySourceVersionId + |
+string + |
+Explanation: +Version ID of the source object. + |
+
VersionId + |
+string + |
+Explanation: +Version ID of the target object. + |
+
You can call ObsClient.copyObject to copy a specific version of an object by specifying versionId in the CopySource parameter. Sample code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an ObsClient instance. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function copyObject() { + try { + const params = { + // Specify the target bucket name. + Bucket: "examplebucket", + // Specify the name of the object copy (example/objectname in this example). + Key: 'example/objectname', + // Specify the source bucket name (sourcebucketname in this example), source object name (sourceobjectkey in this example), and source object version ID (G001117FCE89978B0000401205D5DC9A in this example). + CopySource: 'sourcebucketname/sourceobjectname?versionId=G001117FCE89978B0000401205D5DC9A' + }; + // Copy a version of an object. + const result = await obsClient.copyObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Copy Object(bucket:%s, object: %s) successful from bucket/object: %s!", params.Bucket, params.Key, params.CopySource); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("ETag: %s, LastModified:%s", result.InterfaceResult.ETag, result.InterfaceResult.LastModified); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +copyObject(); + |
To download an object in the Cold storage class, you need to restore it first. After an object is restored, a copy of the object is saved in the Standard storage class. By doing so, the object in the Cold storage class and its copy in the Standard storage class co-exist in the bucket. The copy will be automatically deleted once its retention period ends.
+This API restores a Cold object in a specified bucket.
+ObsClient.restoreObject(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +The object specified in ObsClient.restoreObject must be in the Cold storage class. Otherwise, an error is reported. +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
VersionId + |
+string + |
+No + |
+Explanation: +Version ID of the Cold object to restore. +Restrictions: +None +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 + |
+number + |
+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: +None +Value range: +The value ranges from 1 to 30, in days. +Default value: +None + |
+
Tier + |
++ | +No + |
+Explanation: +Tier of the restoration speed. You can select a suitable tier based on your needs. +Restrictions: +None +Value range: +See Table 2. +Default value: +Standard + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.RestoreTierExpedited + |
+Expedited + |
+Objects can be quickly restored from Cold storage within 1 to 5 minutes. + |
+
ObsClient.enums.RestoreTierStandard + |
+Standard + |
+Objects can be restored from Cold storage within 3 to 5 hours. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example restores version G001117FCE89978B0000401205D5DC9A of Cold object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function restoreObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the version ID of the object. + VersionId: 'G001117FCE89978B0000401205D5DC9A' + // Specify how long the restored object will be retained, in days. The value ranges from 1 to 30 (1 is used in this example). + Days: 1, + // Specify the restore speed (obs.RestoreTierExpedited in this example). By default, the object is restored at an expedited speed. + Tier: obs.enums.RestoreTierExpedited + }; + // Restore the Cold object. + const result = await obsClient.restoreObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Restore object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +restoreObject(); + |
To prolong the validity period of the Cold data restored, you can repeatedly restore the data, but you will be billed for each restoration. After a second restore, the validity period of Standard object copies will be prolonged, and you need to pay for storing these copies during the prolonged period.
+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.
+ObsClient.listVersions(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
KeyMarker + |
+string + |
+No + |
+Explanation: +Object name to start with when listing object versions in a bucket. All object versions following the specified value are listed in lexicographical order by object name. +Restrictions: +This parameter is only available for listing objects with multiple versions. +Value range: +The value can 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 ID of the specified object. +Restrictions: +
Value range: +A version ID of the object specified by KeyMarker +Default value: +None + |
+
Prefix + |
+string + |
+No + |
+Explanation: +Prefix that the object names 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. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
MaxKeys + |
+number + |
+No + |
+Explanation: +The maximum number of objects returned in the response in alphabetical order +Restrictions: +None +Value range: +The value ranges from 1 to 1000. If the specified value is greater than 1000, 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, 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 placed separately into another CommonPrefixes with bbcd as the prefix. +For a parallel file system, if this parameter is not specified, all the content in the directory is recursively listed by default, and subdirectories are also listed. In big data scenarios, parallel file systems usually have multiple directory levels, and each directory level has a large number of objects. In such case, you are advised to configure [Delimiter=/] to list only the content in the current directory, without the content in subdirectories, to make the listing more efficient. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. +Default value: +None + |
+
Location + |
+string + |
+Explanation: +Region where a bucket is located. + |
+
Name + |
+string + |
+Explanation: +Bucket name. + |
+
Prefix + |
+string + |
+Explanation: +Object name prefix, 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, 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. + |
+
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. This parameter corresponds to KeyMarker in the request. + |
+
VersionIdMarker + |
+string + |
+Explanation: +Version ID of the key marker object. +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 ID of the specified object. + |
+
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, 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 placed separately into another CommonPrefixes with bbcd as the prefix. +For a parallel file system, if this parameter is not specified, all the content in the directory is recursively listed by default, and subdirectories are also listed. In big data scenarios, parallel file systems usually have multiple directory levels, and each directory level has a large number of objects. In such case, you are advised to configure [Delimiter=/] to list only the content in the current directory, without the content in subdirectories, to make the listing more efficient. + |
+
MaxKeys + |
+number + |
+Explanation: +The maximum number of objects returned in the response in alphabetical order. This parameter corresponds to MaxKeys in the request. + |
+
IsTruncated + |
+boolean + |
+Explanation: +Whether all results 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: +
|
+
NextKeyMarker + |
+string + |
+Explanation: +Object name to start with in the next request for listing object versions. This parameter is returned if some results were not returned. You can set KeyMarker in the next request to the returned value to list the remaining results. + |
+
NextVersionIdMarker + |
+string + |
+Explanation: +Version ID to start with in the next request for listing object versions. It must be used together with NextKeyMarker. NextVersionIdMarker is returned when some results were not returned. You can set VersionIdMarker in the next request to the returned value to list the remaining results. + |
+
Versions + |
+Version[] + |
+Explanation: +List of object versions in the bucket. For details, see Table 7. + |
+
DeleteMarkers + |
++ | +Explanation: +List of delete markers in the bucket. For details, see Table 8. + |
+
CommonPrefixes + |
+Table 6[] + |
+Explanation: +List of object name prefixes grouped based on the Delimiter parameter (if specified). For details, see CommonPrefix. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Prefix + |
+string + |
+Explanation: +Prefix of objects in the bucket. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + +Value range: +The value can 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 + |
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified, in UTC. +Value range: +UTC time +Default value: +None + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. It uniquely identifies the content of an object and can be used to check the object integrity. For example, if the ETag is A when an object is uploaded and is B when the object is downloaded, it indicates that the object content has been 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 + |
+
Size + |
+number + |
+Explanation: +Object size, in bytes. +Value range: +The value ranges from 0 TB to 48.8 TB, in bytes. +Default value: +None + |
+
Owner + |
++ | +Explanation: +Object owner. For details, see Table 9. + |
+
StorageClass + |
++ | +Explanation: +Storage class of the object. For details, see Table 10. + |
+
IsLatest + |
+boolean + |
+Explanation: +Whether the object is the latest version. +Value range: +
Default value: +false + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + + |
+
VersionId + |
+string + |
+Explanation: +Object version ID. + |
+
IsLatest + |
+boolean + |
+Explanation: +Whether the object is the latest version. +Value range: +
|
+
LastModified + |
+string + |
+Explanation: +Time when the object was last modified, in UTC. + |
+
Owner + |
++ | +Explanation: +Object owner. This parameter contains the domain ID and name of the object owner. For details, see Table 9. + |
+
StorageClass + |
++ | +Explanation: +Storage class of the object. For details, see Table 10. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
This example lists object versions in a bucket. 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 +53 +54 +55 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listVersions() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // List object versions in the bucket. + const result = await obsClient.listVersions(params); + if (result.CommonMsg.Status <= 300) { + console.log("List objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + // Obtain object versions. + for (let j = 0; j < result.InterfaceResult.Versions.length; j++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, VersionId, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.VersionId, val.LastModified, val.Size); + }; + // Obtain delete markers. + for (let i = 0; i < result.InterfaceResult.DeleteMarkers.length; i++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, Key:%s, VersionId, LastModified:%s', + j, val.Owner.ID, val.Key, val.VersionId, val.LastModified); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listVersions(); + |
This example lists a specified number of object versions in 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listVersions() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + }; + // List object versions in the bucket. + const result = await obsClient.listVersions(params); + if (result.CommonMsg.Status <= 300) { + console.log("List version objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + // Obtain object versions. + for (let j = 0; j < result.InterfaceResult.Versions.length; j++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, VersionId, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.VersionId, val.LastModified, val.Size); + }; + // Obtain delete markers. + for (let i = 0; i < result.InterfaceResult.DeleteMarkers.length; i++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, Key:%s, VersionId, LastModified:%s', + j, val.Owner.ID, val.Key, val.VersionId, val.LastModified); + }; + return; + }; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listVersions(); + |
This example lists object versions with a specified prefix.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listVersions() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object prefix (test/ in this example). Objects whose names contain the specified prefix will be listed. + Prefix: "test/", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + }; + + // List object versions in the bucket. + const result = await obsClient.listVersions(params); + if (result.CommonMsg.Status <= 300) { + console.log("List version objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + // Obtain object versions. + for (let j = 0; j < result.InterfaceResult.Versions.length; j++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, VersionId, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.VersionId, val.LastModified, val.Size); + }; + // Obtain delete markers. + for (let i = 0; i < result.InterfaceResult.DeleteMarkers.length; i++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, Key:%s, VersionId, LastModified:%s', + j, val.Owner.ID, val.Key, val.VersionId, val.LastModified); + }; + return; + }; + }; + + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listVersions(); + |
This example lists object versions from the specified 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listVersions() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object prefix (test/ in this example). Objects whose names contain the specified prefix will be listed. + Prefix: "test/", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + // Specify the position (test/test2 in this example) where the object listing starts. + KeyMarker: "test/test2", + }; + // List object versions in the bucket. + const result = await obsClient.listVersions(params); + if (result.CommonMsg.Status <= 300) { + console.log("List version objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + // Obtain object versions. + for (let j = 0; j < result.InterfaceResult.Versions.length; j++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, VersionId, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.VersionId, val.LastModified, val.Size); + }; + // Obtain delete markers. + for (let i = 0; i < result.InterfaceResult.DeleteMarkers.length; i++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, Key:%s, VersionId, LastModified:%s', + j, val.Owner.ID, val.Key, val.VersionId, val.LastModified); + }; + return; + }; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listVersions(); + |
This example lists all object versions 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 +66 +67 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listVersions() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an encoding type. url is used in this example. If the objects to list contain special characters, this parameter must be passed. + EncodingType: "url", + }; + while (true) { + // List object versions in the bucket. + const result = await obsClient.listVersions(params); + if (result.CommonMsg.Status > 300) { + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("List version objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + // Obtain object versions. + for (let j = 0; j < result.InterfaceResult.Versions.length; j++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, VersionId, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.VersionId, val.LastModified, val.Size); + }; + // Obtain delete markers. + for (let i = 0; i < result.InterfaceResult.DeleteMarkers.length; i++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, Key:%s, VersionId, LastModified:%s', + j, val.Owner.ID, val.Key, val.VersionId, val.LastModified); + }; + }; + if (result.InterfaceResult.IsTruncated === "true") { + params.KeyMarker = result.InterfaceResult.NextKeyMarker; + params.VersionIdMarker = result.InterfaceResult.NextVersionIdMarker; + } else { + break; + }; + }; + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listVersions(); + |
All elements stored in OBS buckets are called objects. Folders are 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 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 +62 +63 +64 +65 +66 +67 +68 +69 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listVersions() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object prefix (test/ in this example). Objects whose names contain the specified prefix will be listed. + Prefix: "test/", + // Specify an encoding type. url is used in this example. If the objects to list contain special characters, this parameter must be passed. + EncodingType: "url", + }; + while (true) { + // List object versions in the bucket. + const result = await obsClient.listVersions(params); + if (result.CommonMsg.Status > 300) { + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("List version objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let j = 0; j < result.InterfaceResult.Contents.length; j++) { + // Obtain object versions. + for (let j = 0; j < result.InterfaceResult.Versions.length; j++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, ETag:%s, Key:%s, VersionId, LastModified:%s, Size:%d', + j, val.Owner.ID, val.ETag, val.Key, val.VersionId, val.LastModified, val.Size); + }; + // Obtain delete markers. + for (let i = 0; i < result.InterfaceResult.DeleteMarkers.length; i++) { + const val = result.InterfaceResult.Versions[j]; + console.log('Content[%d]-OwnerId:%s, Key:%s, VersionId, LastModified:%s', + j, val.Owner.ID, val.Key, val.VersionId, val.LastModified); + }; + }; + if (result.InterfaceResult.IsTruncated === "true") { + params.KeyMarker = result.InterfaceResult.NextKeyMarker; + params.VersionIdMarker = result.InterfaceResult.NextVersionIdMarker; + } else { + break; + }; + }; + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listVersions(); + |
This API calls ObsClient.setObjectAcl to set an ACL for an object version specified by the VersionId parameter. For details about the API definition, see Configuring an Object ACL.
+This example sets the ACL to allow all users to read object example/objectname from bucket examplebucket but only allow user 0a03f5833900d3730f13c00f49d5exxx to write.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setObjectAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the version ID of the object. + VersionId: 'G001117FCE89978B0000401205D5DC9A', + // Specify the owner of the object. + Owner: { 'ID': 'ownerid' }, +// Specify the information about the authorized user. + Grants: [ + // Grant the write permission to a specified user (0a03f5833900d3730f13c00f49d5exxx in this example). + { Grantee: { Type: 'CanonicalUser', ID: '0a03f5833900d3730f13c00f49d5exxx' }, Permission: obsClient.enums.PermissionWrite }, + // Grant the read permission to all users. + { Grantee: { Type: 'Group', URI: obsClient.enums.GroupAllUsers }, Permission: obsClient.enums.PermissionRead }, + ] + }; + // Set the ACL. + const result = await obsClient.setObjectAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set Object(%s)'s acl successful with Bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setObjectAcl(); + |
You can call ObsClient.deleteObject to delete an object version specified by the VersionId parameter. For details about the API definition, see Deleting an Object.
+You can also call ObsClient.deleteObjects to delete multiple object versions at a time by passing all of their VersionId values. For details about the API definition, see Batch Deleting Objects.
+This example deletes version G001117FCE89978B0000401205D5DC9A of object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example) to delete. + Key: 'example/objectname', + // Specify the ID of the object version. + VersionId: 'G001117FCE89978B0000401205D5DC9A' + }; + // Delete a version of an object. + const result = await obsClient.deleteObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete object(%s) under the bucket(%s) successful!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteObject(); + |
This example deletes objects objectname1, objectname2, and objectname3 from bucket examplebucket in a batch.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteObjects() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object list to delete. + Objects: [ + { Key: 'objectname1', VersionId: "version1" }, + { Key: 'objectname2', VersionId: "version2" }, + { Key: 'objectname3', VersionId: "version3" } + ] + }; + // Delete the objects in a batch. + const result = await obsClient.deleteObjects(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete objects under the bucket(%s) successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + // Return details about which objects were deleted. + console.log('Deleteds:'); + for (let i = 0; i < result.InterfaceResult.Deleteds.length; i++) { + const deleted = result.InterfaceResult.Deleteds[i]; + console.log("Deleted[%d]-Key:%s, VersionId:%s", i, deleted.Key, deleted.VersionId); + }; + // Return details about which objects were not deleted. + console.log('Errors:'); + for (let i = 0; i < result.InterfaceResult.Errors.length; i++) { + const err = result.InterfaceResult.Errors[i]; + console.log("Errors[%d]-Key:%s, Code:%s", i, err.Key, err.Code); + }; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteObjects(); + |
You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.
+This API configures lifecycle rules for a bucket.
+
ObsClient.setBucketLifecycle(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Rules + |
++ | +Yes + |
+Explanation: +Lifecycle rules of the bucket +Restrictions: +
Value range: +See Table 2. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+No if used as a request parameter + |
+Explanation: +Lifecycle rule ID. +Restrictions: +None +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
Prefix + |
+string + |
+Yes if used as a request parameter + |
+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 alone. If you set Prefix to logs/, the rule applies to objects logs/day1, logs/day2, and logs/day3. If you leave Prefix blank, the rule applies to all objects in the bucket. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
Status + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Whether the current rule is enabled. +Restrictions: +None +Value range: +Enabled +Disabled +Default value: +None + |
+
Transitions + |
++ | +No if used as a request parameter + |
+Explanation: +Policies for storage class transition, including transition time and the storage class after transition. +Restrictions: +This parameter is only available for the latest object version. +Value range: +See Table 3. +Default value: +None + |
+
Expiration + |
++ | +No if used as a request parameter + |
+Explanation: +Expiration time of an object. +Restrictions: +This parameter is only available for the latest object version. +Value range: +See Table 4. +Default value: +None + |
+
NoncurrentVersionTransitions + |
++ | +No if used as a request parameter + |
+Explanation: +Policies for storage class transition of historical versions, including transition time and the storage class after transition. +Restrictions: +
Value range: +See Table 5. +Default value: +None + |
+
NoncurrentVersionExpiration + |
++ | +No if used as a request parameter + |
+Explanation: +Expiration time of historical object versions +Restrictions: +
Value range: +See Table 6. +Default value: +None + |
+
Transitions, Expiration, NoncurrentVersionTransitions, and NoncurrentVersionExpiration cannot be left blank at the same time.
+Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
StorageClass + |
++ | +Yes if used as a request parameter + |
+Explanation: +Storage class of the object after transition +Restrictions: +
Value range: +See Table 7. +Default value: +None + |
+
Date + |
+string + |
+Yes if this parameter is used as a request parameter and Days is absent + |
+Explanation: +OBS executes the lifecycle rule for objects that were modified before the specified date. +Restrictions: +The value must conform with 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. +Value range: +None +Default value: +None + |
+
Days + |
+number + |
+Yes if this parameter is used as a request parameter and Date is absent + |
+Explanation: +How many days can pass since the last update before the lifecycle rule takes effect +Restrictions: +This parameter is only available for the latest object version. +Value range: +0 to (231 – 1), in days +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Date + |
+string + |
+Yes if this parameter is used as a request parameter and Days is absent + |
+Explanation: +OBS executes the lifecycle rule (deletion) for objects that were modified before the specified date. +Restrictions: +The value must conform with 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 deleted. +Value range: +None +Default value: +None + |
+
Days + |
+number + |
+Yes if this parameter is used as a request parameter and Date is absent + |
+Explanation: +How many days can pass since the last update before the lifecycle rule (deletion) takes effect +Restrictions: +This parameter is only available for the latest object version. +Value range: +1 to (231 – 1), in days +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
StorageClass + |
++ | +Yes if used as a request parameter + |
+Explanation: +Storage class of historical object versions after transition +Restrictions: +
Value range: +See Table 7. +Default value: +None + |
+
NoncurrentDays + |
+number + |
+Yes if used as a request parameter + |
+Explanation: +Number of days an object is historical before the specified rule takes effect +Restrictions: +This parameter is only available for historical object versions. +Value range: +0 to (231 – 1), in days +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
NoncurrentDays + |
+number + |
+Yes if used as a request parameter + |
+Explanation: +Number of days an object is historical before the specified rule takes effect +Restrictions: +This parameter is only available for historical object versions. +Value range: +0 to (231 – 1), in days +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 9. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 10. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 11. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example sets lifecycle rules to specify transition policies for latest and historical versions of objects in bucket examplebucket.
+This example sets lifecycle rules to specify expiration time for latest and historical versions of 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 +58 +59 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketLifecycle() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Lifecycle rules + Rules: [ + { + ID:'rule1',Prefix:'prefix1',Status:'Enabled', + // Specify that objects whose names contain the specified prefix will expire 60 days after creation. + Expiration:{Days:60}, + // Specify that objects whose names contain the prefix will expire 60 days after becoming historical. + NoncurrentVersionExpiration:{NoncurrentDays : 60} + }, + { + ID:'rule2',Prefix:'prefix2',Status:'Enabled', + // Specify when the objects whose names contain the specified prefix will expire. The value must conform to the ISO8601 standard. The time value must be 00:00:00 in UTC. + Expiration:{Date: '2018-12-31T00:00:00Z'}, + } + + ] + }; + // Configure lifecycles. + const result = await obsClient.setBucketLifecycle(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s lifecycle configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketLifecycle(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server +Default value: +None + |
+
Rules + |
++ | +Yes +Explanation: +Lifecycle rule information. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
ID + |
+string + |
+Explanation: +Lifecycle rule ID. + |
+
Prefix + |
+string + |
+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 alone. If you set Prefix to logs/, the rule applies to objects logs/day1, logs/day2, and logs/day3. If you leave Prefix blank, the rule applies to all objects in the bucket. + |
+
Status + |
+string + |
+Explanation: +Whether the rule is enabled. +Value range: +Enabled +Disabled + |
+
Transitions + |
++ | +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 latest object version. + |
+
Expiration + |
++ | +Explanation: +Object expiration time. For details, see Table 8. +Restrictions: +This parameter is only available for the latest object version. + |
+
NoncurrentVersionTransitions + |
++ | +Explanation: +Policies for storage class transition, including transition time and the storage class after transition. For details, see Table 9. +Restrictions: +
|
+
NoncurrentVersionExpiration + |
++ | +Explanation: +Expiration time of historical object versions. For details, see Table 10. +Restrictions: +
|
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
StorageClass + |
++ | +Explanation: +Storage class of the object after transition + |
+
Date + |
+string + |
+Explanation: +OBS executes the lifecycle rule for objects that were modified before the specified date. + |
+
Days + |
+number + |
+Explanation: +How many days can pass since the last update before the lifecycle rule takes effect + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Date + |
+string + |
+Explanation: +OBS executes the lifecycle rule (deletion) for objects that were modified before the specified date. + |
+
Days + |
+number + |
+Explanation: +How many days can pass since the last update before the lifecycle rule (deletion) takes effect + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
StorageClass + |
++ | +Explanation: +Storage class of historical object versions after transition + |
+
NoncurrentDays + |
+number + |
+Explanation: +Number of days an object is historical before the specified rule takes effect + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
NoncurrentDays + |
+number + |
+Explanation: +Number of days an object is historical before the specified rule takes effect + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
DaysAfterInitiation + |
+number + |
+Explanation: +Number of days since the initiation of an incomplete multipart upload that OBS will wait before deleting the non-assembled parts (fragments) of the upload + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
You can call ObsClient.getBucketLifecycle to view lifecycle rules of a bucket. The following code shows how to obtain the lifecycle rule 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketLifecycle() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the lifecycle rules of the bucket. + const result = await obsClient.getBucketLifecycle(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s lifecycle configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let i = 0; i < result.InterfaceResult.Rules.length; i++) { + const rule = result.InterfaceResult.Rules[i]; + console.log("ID:%s, Prefix:%s, Status:%s, Expiration[Date]:%s, Expiration[Days]:%d, NoncurrentVersionExpiration[NoncurrentDays]:%s", + rule.ID, rule.Prefix, rule.Status, rule.Expiration.Date, + rule.Expiration.Days, rule.NoncurrentVersionExpiration.NoncurrentDays + ); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketLifecycle(); + |
You can configure lifecycle rules to periodically delete objects or transition objects between storage classes.
+This API deletes the lifecycle rules of a bucket.
+ObsClient.deleteBucketLifecycle(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.deleteBucketLifecycle to delete lifecycle rules of a bucket. The following code shows how to delete the lifecycle rule 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteBucketLifecycle() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // Delete the lifecycle configuration of the bucket. + const result = await obsClient.deleteBucketLifecycle(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s lifecycle configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteBucketLifecycle(); + |
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 normal 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.
+This API configures CORS for a bucket. The configured CORS rules follow the principle of new ones overwriting old ones.
+ObsClient.setBucketCors(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
CorsRules + |
+CorsRule[] + |
+Yes + |
+Explanation: +List of CORS rules of a bucket. +Restrictions: +A list can contain a maximum of 100 CORS rules. +Value range: +See CorsRule. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+No if used as a request parameter + |
+Explanation: +CORS rule ID. +Restrictions: +None +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
AllowedMethod + |
+string[] + |
+Yes if used as a request parameter + |
+Explanation: +The allowed HTTP methods (types of operations on buckets and objects) for a cross-origin request. +Restrictions: +None +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
AllowedOrigin + |
+string[] + |
+Yes if used as a request parameter + |
+Explanation: +The origin that is allowed to access the bucket. +Restrictions: +Domain name of the origin. Each origin can contain at most one wildcard character (*). Example: https://*.vbs.example.com +Value range: +None +Default value: +None + |
+
AllowedHeader + |
+string[] + |
+No if used as a request parameter + |
+Explanation: +The allowed cross-origin request headers. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
MaxAgeSeconds + |
+number + |
+No if used as a request parameter + |
+Explanation: +How long the response can be cached on a client +Restrictions: +Each CORS rule can contain at most one MaxAgeSeconds. +Value range: +0 to (231 – 1), in seconds +Default value: +100 + |
+
ExposeHeader + |
+string[] + |
+No if used as a request parameter + |
+Explanation: +It specifies additional headers a CORS rule allows in a response, which can be used to provide extra information to clients. By default, a browser can access only headers Content-Length and Content-Type. If the browser needs to access other headers, you need to configure them as additional headers. +Restrictions: +Spaces, asterisks (*), ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example configures CORS 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketCors() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify CORS rules. + CorsRules: [ + { + // Specify the allowed request methods, which can be GET, PUT, DELETE, POST, or HEAD. + AllowedMethod: ['GET', 'HEAD', 'PUT'], + // Specify the allowed request origins. + AllowedOrigin: ['http://www.a.com', 'http://www.b.com'], + // Specify whether headers specified in Access-Control-Request-Headers in an OPTIONS preflight request can be used. + AllowedHeader: ['x-obs-header'], + // Specify what headers users can access from application programs. + ExposeHeader: ['x-obs-expose-header'], + // Specify the browser's cache time of the returned results of OPTIONS preflight requests for specific resources, in seconds. + MaxAgeSeconds: 10 + } + ] + }; + // Configure CORS settings for the bucket. + const result = await obsClient.setBucketCors(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s) CORS configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketCors(); + |
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 normal 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.
+This API returns the CORS configuration of a bucket.
+ObsClient.getBucketCors(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
CorsRules + |
+CorsRule[] + |
+Explanation: +CORS rule list of the bucket. For details, see CorsRule. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+No if used as a request parameter + |
+Explanation: +CORS rule ID. +Restrictions: +None +Value range: +The value must contain 1 to 255 characters. +Default value: +None + |
+
AllowedMethod + |
+string[] + |
+Yes if used as a request parameter + |
+Explanation: +The allowed HTTP methods (types of operations on buckets and objects) for a cross-origin request. +Restrictions: +None +Value range: +The following HTTP methods are supported: +
Default value: +None + |
+
AllowedOrigin + |
+string[] + |
+Yes if used as a request parameter + |
+Explanation: +The origin that is allowed to access the bucket. +Restrictions: +Domain name of the origin. Each origin can contain at most one wildcard character (*). Example: https://*.vbs.example.com +Value range: +None +Default value: +None + |
+
AllowedHeader + |
+string[] + |
+No if used as a request parameter + |
+Explanation: +The allowed cross-origin request headers. Only CORS requests matching the allowed headers are valid. +Restrictions: +Each header can contain at most one wildcard character (*). Spaces, ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +Default value: +None + |
+
MaxAgeSeconds + |
+number + |
+No if used as a request parameter + |
+Explanation: +How long the response can be cached on a client +Restrictions: +Each CORS rule can contain at most one MaxAgeSeconds. +Value range: +0 to (231 – 1), in seconds +Default value: +100 + |
+
ExposeHeader + |
+string[] + |
+No if used as a request parameter + |
+Explanation: +It specifies additional headers a CORS rule allows in a response, which can be used to provide extra information to clients. By default, a browser can access only headers Content-Length and Content-Type. If the browser needs to access other headers, you need to configure them as additional headers. +Restrictions: +Spaces, asterisks (*), ampersands (&), colons (:), less-than signs (<), and full-width characters are not allowed. +Value range: +None +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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketCors() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // Obtain the CORS configuration of the bucket. + const result = await obsClient.getBucketCors(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s) CORS configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let k = 0; k < result.InterfaceResult.CorsRules.length; k++) { + const corsRule = result.InterfaceResult.CorsRules[i]; + console.log("ID:%s, AllowedOrigin:%s, AllowedMethod:%s, AllowedHeader:%s, MaxAgeSeconds:%d, ExposeHeader:%s", + corsRule.ID, corsRule.AllowedOrigin.join("|"), corsRule.AllowedMethod.join("|"), corsRule.AllowedHeader.join("|"), + corsRule.MaxAgeSeconds, corsRule.ExposeHeader.join("|") + ); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketCors(); + |
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 normal 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.
+This API deletes the CORS rules of a bucket.
+ObsClient.deleteBucketCors(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Sample code is as follows:
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteBucketCors() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Delete CORS rules of the bucket. + const result = await obsClient.DeleteBucketCors(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s CORS configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("Delete bucket(%s)'s CORS configuration successful!", params.Bucket); + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteBucketCors(); + |
A bucket in the Warm or Cold storage class cannot be used as a log target bucket.
+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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Agency + |
+string + |
+Yes if used in a request for enabling bucket logging + |
+Explanation: +Name of the IAM agency created by the owner of the target bucket for OBS. +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. +Value range: +You can select an existing IAM agency or create one. +Default value: +None + |
+
LoggingEnabled + |
++ | +Yes if you enable logging for the bucket +Do not set this parameter when you disable logging for the bucket. + |
+Explanation: +Logging configuration information. If this parameter is not set, bucket logging is disabled by default. +Restrictions: +None +Value range: +See LoggingEnabled. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
TargetBucket + |
+string + |
+Yes if you enable logging for the bucket +Do not set this parameter when you disable logging for the bucket. + |
+Explanation: +Name of the bucket for storing log files. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
TargetPrefix + |
+string + |
+Yes if you enable logging for the bucket +Do not set this parameter when you disable logging for the bucket. + |
+Explanation: +Name prefix for log files stored in the target bucket. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
TargetGrants + |
++ | +No + |
+Explanation: +Permission information list of grantees, which defines grantees and their permissions for log files. +Restrictions: +None +Value range: +See Grant. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Grantee + |
++ | +Yes + |
+Explanation: +Grantees and permissions +Restrictions: +None +Value range: +See Grantee. +Default value: +None + |
+
Permission + |
++ | +Yes + |
+Explanation: +Granted permission +Restrictions: +None +Value range: +See PermissionType. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Type + |
++ | +Yes if used as a request parameter + |
+Explanation: +Grantee type +Restrictions: +None +Value range: +See Table 5. +Default value: +None + |
+
ID + |
+string + |
+Yes if this parameter is used as a request parameter and Type is set to a user + |
+Explanation: +Account (domain) ID of the grantee. +Restrictions: +None +Default value: +None + |
+
Name + |
+string + |
+No if used as a request parameter + |
+Explanation: +Account name of the grantee. +Restrictions: +
Value range: +None +Default value: +None + |
+
URI + |
++ | +Yes if this parameter is used as a request parameter and Type is set to a group + |
+Explanation: +Authorized user group +Restrictions: +None +Value range: +See Table 6. +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
GranteeGroup + |
+Group + |
+Grants permissions to user groups. + |
+
GranteeUser + |
+CanonicalUser + |
+Grants permissions to individual users. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
GroupAllUsers + |
+AllUsers + |
+All users + |
+
GroupAuthenticatedUsers + |
+AuthenticatedUsers + |
+Authorized users. This constant is deprecated. + |
+
GroupLogDelivery + |
+LogDelivery + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.PermissionRead + |
+READ + |
+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. + |
+
ObsClient.enums.PermissionWrite + |
+WRITE + |
+A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not applicable to objects. + |
+
ObsClient.enums.PermissionReadAcp + |
+READ_ACP + |
+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. + |
+
ObsClient.enums.PermissionWriteAcp + |
+WRITE_ACP + |
+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. + |
+
ObsClient.enums.PermissionFullControl + |
+FULL_CONTROL + |
+A grantee with this permission for a bucket has PermissionRead, PermissionWrite, PermissionReadAcp, and PermissionWriteAcp permissions for the bucket. +A grantee with this permission for an object has PermissionRead, PermissionReadAcp, and PermissionWriteAcp permissions for the object. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 9. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 10. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 11. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example configures logging 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketLogging() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an agency name (obs_test_agency in this example). + Agency: 'obs_test_agency', + LoggingEnabled: { + // Specify a bucket (TargetBucketname in this example) for storing generated log files. + TargetBucket: 'TargetBucketname', + // Specify a prefix (TargetPrefixtest/ in this example) for log files to be generated. + TargetPrefix: 'TargetPrefixtest/', + // Specify the grantee permissions. + TargetGrants: [ + // Grant the read permission to a specific user. In this example, the user ID is 0a03f5833900d3730f13c00f49d5exxx. + { Grantee: { Type: 'CanonicalUser', ID: '0a03f5833900d3730f13c00f49d5exxx' }, Permission: obsClient.enums.PermissionRead } + ] + } + }; + // Configure logging for a bucket. + const result = await obsClient.setBucketLogging(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s logging configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketLogging(); + |
This example disables logging 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketLogging() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Clear the logging configuration. + LoggingEnabled : {} + }; + // Delete the access logging configuration of the bucket. + const result = await obsClient.setBucketLogging(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s logging configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketLogging(); + |
This API returns the logging configuration of a bucket.
+ObsClient.getBucketLogging(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Agency + |
+string + |
+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. + |
+
LoggingEnabled + |
++ | +Explanation: +Logging configuration information + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
TargetBucket + |
+string + |
+Explanation: +Name of the bucket for storing log files. + |
+
TargetPrefix + |
+string + |
+Explanation: +Name prefix for log files stored in the target bucket. + |
+
TargetGrants + |
++ | +Explanation: +Permission information list of grantees, which defines grantees and their permissions for log files. For details, see Table 7. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Grantee + |
++ | +Yes if used as a request parameter + |
+Explanation: +Grantee information. For details, see Table 8. + |
+
Permission + |
++ | +Yes if used as a request parameter + |
+Explanation: +Granted permissions. For details, see Table 11. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Type + |
++ | +Yes if used as a request parameter + |
+Explanation: +Grantee type. For details, see Table 9. + |
+
ID + |
+string + |
+Yes if this parameter is used as a request parameter and Type is set to a user + |
+Explanation: +Account (domain) ID of the grantee. + |
+
Name + |
+string + |
+No if used as a request parameter + |
+Explanation: +Account name of the grantee. + |
+
URI + |
++ | +Yes if this parameter is used as a request parameter and Type is set to a group + |
+Explanation: +Authorized user group. For details, see Table 10. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
GranteeGroup + |
+Group + |
+Grants permissions to user groups. + |
+
GranteeUser + |
+CanonicalUser + |
+Grants permissions to individual users. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
GroupAllUsers + |
+AllUsers + |
+All users + |
+
GroupAuthenticatedUsers + |
+AuthenticatedUsers + |
+Authorized users. This constant is deprecated. + |
+
GroupLogDelivery + |
+LogDelivery + |
+Log delivery group. This constant is deprecated. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.PermissionRead + |
+READ + |
+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. + |
+
ObsClient.enums.PermissionWrite + |
+WRITE + |
+A grantee with this permission for a bucket can upload, overwrite, and delete any object or part in the bucket. +This permission is not applicable to objects. + |
+
ObsClient.enums.PermissionReadAcp + |
+READ_ACP + |
+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. + |
+
ObsClient.enums.PermissionWriteAcp + |
+WRITE_ACP + |
+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. + |
+
ObsClient.enums.PermissionFullControl + |
+FULL_CONTROL + |
+A grantee with this permission for a bucket has PermissionRead, PermissionWrite, PermissionReadAcp, and PermissionWriteAcp permissions for the bucket. +A grantee with this permission for an object has PermissionRead, PermissionReadAcp, and PermissionWriteAcp permissions for the object. + |
+
You can call ObsClient.getBucketLogging to view the logging configuration of a bucket. The following code shows how to obtain 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 +49 +50 +51 +52 +53 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketLogging() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // Obtain logging for a bucket. + const result = await obsClient.getBucketLogging(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s logging configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + if (result.InterfaceResult.LoggingEnabled) { + console.log('TargetBucket: %s', result.InterfaceResult.LoggingEnabled.TargetBucket); + console.log('TargetPrefix: %s', result.InterfaceResult.LoggingEnabled.TargetPrefix); + for (let i = 0; i < result.InterfaceResult.LoggingEnabled.TargetGrants.length; i++) { + const grant = result.InterfaceResult.LoggingEnabled.TargetGrants[0]; + console.log('Grant[%d]-Type:%s, ID:%s, URI:%s, Permission:%s', + i, grant.Grantee.Type, grant.Grantee.ID, grant.Grantee.URI, grant.Permission + ); + }; + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketLogging(); + |
You can upload the content files of the static website to your bucket in OBS as objects and configure the public-read permission on the files, and then configure the static website hosting mode for your bucket to host your static websites in OBS. 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.
+You can perform the following to host a website file in a bucket:
+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 | // Import the OBS library. +// Use npm for installation. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code for installation. +// var ObsClient = require('./lib/obs'); + +// Create an ObsClient instance. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function putObject() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. test.html is used in this example. + Key: 'test.html', + Body: '<html><header></header><body><h1>Hello OBS</h1></body></html>', + // Set the MIME type for the object. + ContentType: 'text/html', + // Set the object ACL to public read. + ACL: obsClient.enums.AclPublicRead + + }; + // Upload the object. + const result = await obsClient.putObject(params); + if (result.CommonMsg.Status <= 300) { + console.log("Put object(%s) under the bucket(%s) successful!!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("StorageClass:%s, ETag:%s", result.InterfaceResult.StorageClass, result.InterfaceResult.ETag); + return; + } + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.") + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.") + console.log(error); + } +} + +putObject(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
RedirectAllRequestsTo + |
++ | +No + |
+Explanation: +Redirection rule for all requests +Restrictions: +None +Value range: +See Table 2. +Default value: +None + |
+
IndexDocument + |
++ | +No + |
+Explanation: +Default page configuration. +Restrictions: +None +Value range: +See Table 3. +Default value: +None + |
+
ErrorDocument + |
++ | +No + |
+Explanation: +Error page configuration. +Restrictions: +None +Value range: +See Table 4. +Default value: +None + |
+
RoutingRules + |
++ | +No + |
+Explanation: +Redirection rule list +Restrictions: +None +Value range: +See Table 5. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
HostName + |
+string + |
+Yes if RedirectAllRequestsTo is specified + |
+Explanation: +Domain name used for redirection, for example, www.example.com +Restrictions: +The domain name must comply with the domain name standards. +Value range: +None +Default value: +None + |
+
Protocol + |
+string + |
+No + |
+Explanation: +Protocol used for redirection +Restrictions: +None +Value range: +http or https +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Suffix + |
+string + |
+Yes if IndexDocument is specified + |
+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: +This parameter can neither be left blank nor contain slashes (/). +Value range: +None +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Key + |
+string + |
+No if ErrorDocument is specified + |
+Explanation: +The object name that is used when a 4XX error occurs. This element specifies the page that is returned when an error occurs. +Restrictions: +None +Value range: +The key can contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Condition + |
++ | +No + |
+Explanation: +Conditions that must be met for the specified rule to take effect +Restrictions: +None +Value range: +See Table 6. +Default value: +None + |
+
Redirect + |
++ | +Yes if RoutingRule is specified + |
+Explanation: +Details about the redirection +Restrictions: +None +Value range: +See Table 7. +Default value: +None + |
+
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 can contain 1 to 1,024 characters. +Default value: +None + |
+
HttpErrorCodeReturnedEquals + |
+string + |
+No + |
+Explanation: +HTTP error code for the redirection to take effect. If an 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 Condition 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 + |
+string + |
+No if used as a request parameter + |
+Explanation: +Protocol used for redirection +Restrictions: +None +Value range: +http or https +Default value: +None + |
+
HostName + |
+string + |
+No if used as a request parameter + |
+Explanation: +Domain name used for redirection +Restrictions: +The domain name must comply with the domain name standards. +Value range: +None +Default value: +None + |
+
ReplaceKeyPrefixWith + |
+string + |
+No if used as a request parameter + |
+Explanation: +Object name prefix used in the redirection request +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
ReplaceKeyWith + |
+string + |
+No if used as a request parameter + |
+Explanation: +Object name used in the redirection request +Restrictions: +This parameter cannot be used together with replaceKeyPrefixWith. +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
HttpRedirectCode + |
+string + |
+No if used as a request parameter + |
+Explanation: +HTTP status code in the response to the redirection request +Restrictions: +None +Value range: + +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. +For details, see Table 9. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 10. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 11. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example configures website hosting 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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketWebsite() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify a default page (index.html in this example). + IndexDocument: { Suffix: 'index.html' }, + // Specify an error page (error.html in this example). + ErrorDocument: { Key: 'error.html' }, + // Configure redirection for all requests. + RedirectAllRequestsTo : {HostName : 'www.example.com', Protocol : 'http'} + // Specify redirect rules for requests. + RoutingRules: [ + { Redirect: { HostName: "www.a.com", Protocol: obs.ProtocolHttp, ReplaceKeyPrefixWith: "prefix", HttpRedirectCode: "304" } }, + { Redirect: { HostName: "www.b.com", Protocol: obs.ProtocolHttps, ReplaceKeyWith: "replaceKey", HttpRedirectCode: "304" } }, + ] + }; + // Configure the website settings for the bucket. + const result = await obsClient.setBucketWebsite(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s website configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketWebsite(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
RedirectAllRequestsTo + |
++ | +Explanation: +Redirection rules for all requests. For details, see Table 8. + |
+
IndexDocument + |
++ | +Explanation: +Default page configuration. For details, see Table 6. + |
+
ErrorDocument + |
++ | +Explanation: +Error page configuration. For details, see Table 7. + |
+
RoutingRules + |
++ | +Explanation: +List of routing rules. For details, see Table 9. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Suffix + |
+string + |
+Yes if IndexDocument is specified + |
+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: +This parameter can neither be left blank nor contain slashes (/). +Value range: +None +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Key + |
+string + |
+No if ErrorDocument is specified + |
+Explanation: +The object name that is used when a 4XX error occurs. This element specifies the page that is returned when an error occurs. +Restrictions: +None +Value range: +The key can contain 1 to 1,024 characters. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
HostName + |
+string + |
+Explanation: +Domain name used for redirection, for example, www.example.com + |
+
Protocol + |
+string + |
+Explanation: +Protocol used for redirection + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Condition + |
++ | +Explanation: +Conditions that must be met for the specified rule to take effect. For details, see Condition. + + |
+
Redirect + |
++ | +Explanation: +Details about the redirection. For details, see Table 11. + |
+
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 can contain 1 to 1,024 characters. +Default value: +None + |
+
HttpErrorCodeReturnedEquals + |
+string + |
+No + |
+Explanation: +HTTP error code for the redirection to take effect. If an 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 Condition and set ReplaceKeyWith to NotFound.html in Redirect. +Restrictions: +This parameter cannot be used together with KeyPrefixEquals. +Default value: +None + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Protocol + |
+string + |
+Explanation: +Protocol used for redirection + |
+
HostName + |
+string + |
+Explanation: +Domain name used for redirection + |
+
ReplaceKeyPrefixWith + |
+string + |
+Explanation: +Object name prefix used in the redirection request + |
+
ReplaceKeyWith + |
+string + |
+Explanation: +Object name used in the redirection request + |
+
HttpRedirectCode + |
+string + |
+Explanation: +HTTP status code in the response to the redirection request. + |
+
You can call ObsClient.getBucketWebsite to obtain the hosting configuration of a bucket. The following code shows how to obtain the website 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketWebsite() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // Obtain the website configuration of the bucket. + const result = await obsClient.getBucketWebsite(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s website configuration successful!", params.Bucket); + console.log('RedirectAllRequestsTo:'); + console.log('HostName: %s', result.InterfaceResult.RedirectAllRequestsTo.HostName); + console.log('Protocol: %s', result.InterfaceResult.RedirectAllRequestsTo.Protocol); + console.log('IndexDocument[Suffix]: %s', result.InterfaceResult.IndexDocument.Suffix); + console.log('ErrorDocument[Key]: %s', result.InterfaceResult.ErrorDocument.Key); + console.log('RoutingRules:'); + for (let i = 0; i < result.InterfaceResult.RoutingRules; i++) { + let routingRule = result.InterfaceResult.RoutingRules[i]; + let condition = routingRule.Condition; + console.log("Condition[%d]-KeyPrefixEquals:%s, HttpErrorCodeReturnedEquals:%s", + i, condition.KeyPrefixEquals, condition.HttpErrorCodeReturnedEquals + ); + let redirect = routingRule.Redirect; + console.log("Redirect[%d]-Protocol:%s, HostName:%s, ReplaceKeyPrefixWith:%s, HttpRedirectCode:%s", + i, redirect.Protocol, redirect.HostName, redirect.ReplaceKeyPrefixWith, redirect.HttpRedirectCode + ); + }; + return; + }; + + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getBucketWebsite(); + |
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(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.deleteBucketWebsite to delete the hosting configuration of a bucket. The following code shows how to delete the website 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs') +; +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteBucketWebsite() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + }; + // Delete the website configuration of the bucket. + const result = await obsClient.deleteBucketWebsite(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s website configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteBucketWebsite(); + |
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 data to a bucket when it is running, you can tag the bucket with the name of this application. Then, you can analyze the cost of this application by using that tag.
+This API adds tags to a bucket.
+ +ObsClient.setBucketTagging(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Tags + |
+Tag[] + |
+Yes + |
+Explanation: +Bucket tag set. +Restrictions: +
Value range: +See Tag. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
The following code shows how to set tags 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function setBucketTagging() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify bucket tags. + Tags: [ + {Key: "key0", Value: "value0"}, + {Key: "key1", Value: "value1"}, + ] + }; + // Set bucket tags. + const result = await obsClient.setBucketTagging(params); + if (result.CommonMsg.Status <= 300) { + console.log("Set bucket(%s)'s tagging configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +setBucketTagging(); + |
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 data to a bucket when it is running, you can tag the bucket with the name of this application. Then, you can analyze the cost of this application by using that tag.
+This API returns the tags of a bucket.
+ +ObsClient.getBucketTagging(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Tags + |
+Tag[] + |
+Explanation: +Bucket tag list. For details, see Table 6. + |
+
You can call ObsClient.getBucketTagging to view bucket tags. The following code shows how to obtain the tag 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getBucketTagging() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Obtain the bucket tag configuration. + const result = await obsClient.getBucketTagging(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get bucket(%s)'s tagging configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let tag of result.InterfaceResult.Tags) { + console.log('Key: %s, Value: %s', tag.key, tag.value); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; +getBucketTagging(); + |
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 data to a bucket when it is running, you can tag the bucket with the name of this application. Then, you can analyze the cost of this application by using that tag.
+This API deletes the tags of a bucket.
+ +ObsClient.deleteBucketTagging(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
You can call ObsClient.deleteBucketTagging to delete bucket tags. The following code shows how to delete the tags 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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + //Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + //Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function deleteBucketTagging() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket" + }; + // Delete the bucket tag configuration. + const result = await obsClient.deleteBucketTagging(params); + if (result.CommonMsg.Status <= 300) { + console.log("Delete bucket(%s)'s tagging configuration successful!", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("Delete bucket(%s)'s tagging configuration fail!", params.Bucket); + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +deleteBucketTagging(); + |
This API calls ObsClient.getObjectAcl to obtain the ACL of an object version specified by the VersionId parameter. For details about the API definition, see Obtaining the ACL of an Object.
+This example obtains the ACL of version G001117FCE89978B0000401205D5DC9A of object example/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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function getObjectAcl() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example). + Key: 'example/objectname', + // Specify the version ID of the object. + VersionId: 'G001117FCE89978B0000401205D5DC9A' + }; + // Obtain the object ACL. + const result = await obsClient.getObjectAcl(params); + if (result.CommonMsg.Status <= 300) { + console.log("Get object(%s)'s acl successful with bucket(%s)!", params.Key, params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log('Owner[ID]: %s', result.InterfaceResult.Owner.ID); + console.log('Owner[Name]: %s', result.InterfaceResult.Owner.Name); + for (let i = 0; i < result.InterfaceResult.Grants.length; i++) { + const grant = result.InterfaceResult.Grants[i]; + fmt.Printf("Grant[%d]-Type:%s, ID:%s, URI:%s, Permission:%s\n", + index, grant.Grantee.Type, grant.Grantee.ID, grant.Grantee.URI, grant.Permission); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +getObjectAcl(); + |
The following table lists APIs related to server-side encryption:
+ +Method in OBS Node.js 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.appendObject + |
+Sets the encryption algorithm and key during appendable upload to enable server-side encryption. + |
+SSE-KMS +SSE-C + |
+
ObsClient.getObject + |
+Sets the decryption algorithm and key during object download to decrypt the object. + |
+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 + |
+
OBS Node.js SDK supports the following two types of encryption/decryption mode:
+ +Encryption/Decryption Type + |
+Request Parameter + |
+Description + |
+
|---|---|---|
SSE-KMS + + |
+SseKms + |
+Indicates that SSE-KMS mode is used. Currently, only kms is supported. + |
+
SseKmsKey + |
+Indicates the master key used in SSE-KMS mode. The value can be null. + |
+|
SSE-C + |
+SseC + |
+Indicates that SSE-C mode is used. Currently, only AES256 is supported. + |
+
SseCKey + |
+Indicates the key in SSE-C mode. It is calculated using the AES256 algorithm. This parameter can be used to encrypt an object to be uploaded and decrypt an object to be downloaded. + |
+|
CopySourceSseC + |
+Indicates the source object decrypted in SSE-C mode. The value can only be AES256. This parameter is applicable to ObsClient.copyObject and ObsClient.copyPart. + |
+|
CopySourceSseCKey + |
+Indicates the key used by a source object for decryption in SSE-C mode. It is calculated using the AES256 algorithm. This parameter is applicable to ObsClient.copyObject and ObsClient.copyPart. + |
+
This example uploads object example/objectname to bucket examplebucket and encrypts it using SSE-C.
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function putObject() {
+ try {
+ const params = {
+ // Specify the bucket name.
+ Bucket: "examplebucket",
+ // Specify an object. example/objectname is used in this example.
+ Key: "example/objectname",
+ // Specify a text object.
+ Body : 'Hello OBS',
+ // Specify SSE-C as the encryption algorithm.
+ SseC: 'AES256',
+ SseCKey: 'your sse-c key generated by AES-256 algorithm'
+ };
+ // Upload and encrypt the object.
+ const result = await obsClient.putObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Put object(%s) under the bucket(%s) successful!", params.Bucket);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+putObject();
+This example downloads the encrypted object example/objectname using a stream.
+// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require("esdk-obs-nodejs");
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+async function getObject() {
+ try {
+ const params = {
+ // Specify the bucket name.
+ Bucket: "examplebucket",
+ // Specify the object (example/objectname in this example).
+ Key: 'example/objectname',
+ // Specify SSE-C as the algorithm.
+ SseC: 'AES256',
+ // Specify the same key you used for encrypting the object during the upload.
+ SseCKey: 'your sse-c key generated by AES-256 algorithm'
+ };
+
+ // Download the encrypted object.
+ const result = await obsClient.getObject(params);
+ if (result.CommonMsg.Status <= 300) {
+ console.log("Get object(%s) under the bucket(%s) successful!", params.Key, params.Bucket);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ console.log('Object Content: %s', result.InterfaceResult.Content);
+ return;
+ };
+ console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response.");
+ console.log("Status: %d", result.CommonMsg.Status);
+ console.log("Code: %s", result.CommonMsg.Code);
+ console.log("Message: %s", result.CommonMsg.Message);
+ console.log("RequestId: %s", result.CommonMsg.RequestId);
+ } catch (error) {
+ console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.");
+ console.log(error);
+ };
+};
+
+getObject();
+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.
+ +Error Code + |
+Description + |
+HTTP Status Code + |
+
|---|---|---|
AccessDenied + |
+Access denied. + |
+403 Forbidden + |
+
AccessForbidden + |
+Insufficient permission. + |
+403 Forbidden + |
+
AccountProblem + |
+Your account is abnormal (for example, it has been expired or frozen). + |
+403 Forbidden + |
+
AllAccessDisabled + |
+You have no permission to perform the operation. + |
+403 Forbidden + |
+
AmbiguousGrantByEmailAddress + |
+The provided email address is associated with more than one account. + |
+400 Bad Request + |
+
BadDigest + |
+The specified value of Content-MD5 does not match the value received by OBS. + |
+400 Bad Request + |
+
BadDomainName + |
+Invalid domain name. + |
+400 Bad Request + |
+
BadRequest + |
+Invalid request parameters. + |
+400 Bad Request + |
+
BucketAlreadyExists + |
+The requested bucket name already exists. The bucket namespace is shared by all users of OBS. Select another name and retry. + |
+409 Conflict + |
+
BucketAlreadyOwnedByYou + |
+Your previous request for creating the named bucket succeeded and you already own it. + |
+409 Conflict + |
+
BucketNotEmpty + |
+The bucket that you tried to delete is not empty. + |
+409 Conflict + |
+
CredentialsNotSupported + |
+This request does not support security credentials. + |
+400 Bad Request + |
+
CustomDomainAreadyExist + |
+The configured domain already exists. + |
+400 Bad Request + |
+
CustomDomainNotExist + |
+The domain to be operated does not exist. + |
+400 Bad Request + |
+
DeregisterUserId + |
+The user has been deregistered. + |
+403 Forbidden + |
+
EntityTooSmall + |
+The size of the object to be uploaded is smaller than the lower limit. + |
+400 Bad Request + |
+
EntityTooLarge + |
+The size of the object to be uploaded has exceeded the upper limit. + |
+400 Bad Request + |
+
FrozenUserId + |
+The user has been frozen. + |
+403 Forbidden + |
+
IllegalVersioningConfiguration Exception + |
+Invalid versioning configuration in the request. + |
+400 Bad Request + |
+
IllegalLocationConstraintException + |
+The configured region limitation is inconsistent with the region where it resides. + |
+400 Bad Request + |
+
InArrearOrInsufficientBalance + |
+The user has no permission to perform some operations due to being in arrears or insufficient funds. + |
+403 Forbidden + |
+
IncompleteBody + |
+Incomplete request body. + |
+400 Bad Request + |
+
IncorrectNumberOfFilesInPost Request + |
+Each POST request must contain one file to be uploaded. + |
+400 Bad Request + |
+
InlineDataTooLarge + |
+The size of inline data has exceeded the upper limit. + |
+400 Bad Request + |
+
InsufficientStorageSpace + |
+Insufficient storage space. + |
+403 Forbidden + |
+
InternalError + |
+An internal error occurs. Retry later. + |
+500 Internal Server Error + |
+
InvalidAccessKeyId + |
+The access key ID provided by the customer does not exist in the system. + |
+403 Forbidden + |
+
InvalidAddressingHeader + |
+The anonymous role must be specified. + |
+N/A + |
+
InvalidArgument + |
+Invalid parameter. + |
+400 Bad Request + |
+
InvalidBucketName + |
+The specified bucket name in the request is invalid. + |
+400 Bad Request + |
+
InvalidBucket + |
+The bucket to be accessed does not exist. + |
+400 Bad Request + |
+
InvalidBucketState + |
+Invalid bucket status. + |
+409 Conflict + |
+
InvalidBucketStoragePolicy + |
+An invalid new policy is specified during bucket policy modification. + |
+400 Bad Request + |
+
InvalidDigest + |
+The specified Content-MD5 in the HTTP header is invalid. + |
+400 Bad Request + |
+
InvalidEncryptionAlgorithmError + |
+Incorrect encryption algorithm. + |
+400 Bad Request + |
+
InvalidLocationConstraint + |
+The location specified during bucket creation is invalid. + |
+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. + |
+400 Bad Request + |
+
InvalidPartOrder + |
+Parts are not listed in ascending order by part number. + |
+400 Bad Request + |
+
InvalidPayer + |
+All accesses to this object are disabled. + |
+403 Forbidden + |
+
InvalidPolicyDocument + |
+The content of the form does not meet the conditions specified in the policy document. + |
+400 Bad Request + |
+
InvalidRange + |
+The requested range cannot be obtained. + |
+416 Client Requested Range Not Satisfiable + |
+
InvalidRedirectLocation + |
+Invalid redirect location. + |
+400 Bad Request + |
+
InvalidRequest + |
+Invalid request. + |
+400 Bad Request + |
+
InvalidRequestBody + |
+Invalid POST request body. + |
+400 Bad Request + |
+
InvalidSecurity + |
+Invalid security credentials. + |
+403 Forbidden + |
+
InvalidStorageClass + |
+Invalid storage class. + |
+400 Bad Request + |
+
InvalidTargetBucketForLogging + |
+The delivery group has no ACL permission for the target bucket. + |
+400 Bad Request + |
+
InvalidURI + |
+The specified URI cannot be resolved. + |
+400 Bad Request + |
+
KeyTooLong + |
+The provided key is too long. + |
+400 Bad Request + |
+
MalformedACLError + |
+The provided XML file has syntax errors or does not meet the format requirements. + |
+400 Bad Request + |
+
MalformedError + |
+The XML format in the request is incorrect. + |
+400 Bad Request + |
+
MalformedLoggingStatus + |
+The XML format of Logging is incorrect. + |
+400 Bad Request + |
+
MalformedPolicy + |
+The bucket policy failed the check. + |
+400 Bad Request + |
+
MalformedPOSTRequest + |
+The body of the POST request is in an incorrect format. + |
+400 Bad Request + |
+
MalformedQuotaError + |
+The Quota XML format is incorrect. + |
+400 Bad Request + |
+
MalformedXML + |
+This error code is returned after you send an XML file in incorrect format, stating "The XML you provided was not well-formed or did not validate against our published schema." + |
+400 Bad Request + |
+
MaxMessageLengthExceeded + |
+The request is too long. + |
+400 Bad Request + |
+
MaxPostPreDataLengthExceeded Error + |
+The POST request fields prior to the file to be uploaded are too large. + |
+400 Bad Request + |
+
MetadataTooLarge + |
+The size of the metadata header has exceeded the upper limit. + |
+400 Bad Request + |
+
MethodNotAllowed + |
+The specified method is not allowed against the requested resource. +The message "Specified method is not supported." is returned. + |
+405 Method Not Allowed + |
+
MissingContentLength + |
+The HTTP header Content-Length is not provided. + |
+411 Length Required + |
+
MissingRegion + |
+No region contained in the request and no default region defined in the system. + |
+400 Bad Request + |
+
MissingRequestBodyError + |
+This error code is returned after you send an empty XML file, stating "Request body is empty." + |
+400 Bad Request + |
+
MissingRequiredHeader + |
+Required headers missing in the request. + |
+400 Bad Request + |
+
MissingSecurityHeader + |
+A required header is not provided. + |
+400 Bad Request + |
+
NoSuchBucket + |
+The specified bucket does not exist. + |
+404 Not Found + |
+
NoSuchBucketPolicy + |
+No bucket policy exists. + |
+404 Not Found + |
+
NoSuchCORSConfiguration + |
+No CORS configuration exists. + |
+404 Not Found + |
+
NoSuchCustomDomain + |
+The requested user domain does not exist. + |
+404 Not Found + |
+
NoSuchKey + |
+The specified key does not exist. + |
+404 Not Found + |
+
NoSuchLifecycleConfiguration + |
+The requested Lifecycle does not exist. + |
+404 Not Found + |
+
NoSuchPolicy + |
+The specified policy name does not exist. + |
+404 Not Found + |
+
NoSuchUpload + |
+The specified multipart upload does not exist. The upload ID does not exist or the multipart upload has been aborted or completed. + |
+404 Not Found + |
+
NoSuchVersion + |
+The specified version ID does not match any existing version. + |
+404 Not Found + |
+
NoSuchWebsiteConfiguration + |
+The requested website does not exist. + |
+404 Not Found + |
+
NotImplemented + |
+The provided header implies a function that is unavailable. + |
+501 Not Implemented + |
+
NotSignedUp + |
+Your account has not registered in the system. + |
+403 Forbidden + |
+
OperationAborted + |
+A conflicting operation is being performed on this resource. Retry later. + |
+409 Conflict + |
+
PermanentRedirect + |
+The requested bucket has been permanently redirected to a new URL. All future requests must be sent to the new URL. + |
+301 Moved Permanently + |
+
PreconditionFailed + |
+At least one of the specified preconditions is not met. + |
+412 Precondition Failed + |
+
Redirect + |
+The request is temporarily redirected. + |
+307 Moved Temporarily + |
+
RequestIsNotMultiPartContent + |
+A bucket POST request must contain an enclosure-type multipart or the form-data. + |
+400 Bad Request + |
+
RequestTimeout + |
+The socket connection to the server has no read or write operations within the timeout period. + |
+400 Bad Request + |
+
RequestTimeTooSkewed + |
+The request time and the server's time differ a lot. + |
+403 Forbidden + |
+
RequestTorrentOfBucketError + |
+Requesting the bucket's torrent file is not allowed. + |
+400 Bad Request + |
+
ServiceNotImplemented + |
+The request method is not implemented by the server. + |
+501 Not Implemented + |
+
ServiceNotSupported + |
+The request method is not supported by the server. + |
+409 Conflict + |
+
ServiceUnavailable + |
+The server is overloaded or has internal errors. + |
+503 Service Unavailable + |
+
SignatureDoesNotMatch + |
+The provided signature does not match the signature calculated by OBS. Check your AK/SK and signature calculation method. + |
+403 Forbidden + |
+
SlowDown + |
+Too frequent requests. Reduce your request frequency. + |
+503 Service Unavailable + |
+
System Capacity Not enough + |
+Insufficient system space. + |
+403 Forbidden + |
+
TooManyCustomDomains + |
+Too many user domains are configured. + |
+400 Bad Request + |
+
TemporaryRedirect + |
+The request is redirected to the bucket while the domain name server (DNS) is being updated. + |
+307 Moved Temporarily + |
+
TooManyBuckets + |
+You have attempted to create more buckets than allowed. + |
+400 Bad Request + |
+
TooManyObjectCopied + |
+An object has been copied too many times. + |
+400 Bad Request + |
+
TooManyWrongSignature + |
+The request is rejected due to high-frequency errors. + |
+400 Bad Request + |
+
UnexpectedContent + |
+This request does not support content. + |
+400 Bad Request + |
+
UnresolvableGrantByEmailAddress + |
+The provided email address does not match any recorded accounts. + |
+400 Bad Request + |
+
UserKeyMustBeSpecified + |
+The user's AK is not carried in the request. + |
+400 Bad Request + |
+
WebsiteRedirect + |
+The website request lacks bucketName. + |
+301 Moved Permanently + |
+
KMS.DisabledException + |
+The master key is disabled in server-side encryption with KMS-managed keys (SSE-KMS) mode. + |
+400 Bad Request + |
+
KMS.NotFoundException + |
+The master key does not exist in SSE-KMS mode. + |
+400 Bad Request + |
+
RestoreAlreadyInProgress + |
+The objects are being restored. The request conflicts with another one. + |
+409 Conflict + |
+
ObjectHasAlreadyRestored + |
+The objects have been restored and the retention period of the objects cannot be shortened. + |
+409 Conflict + |
+
InvalidObjectState + |
+The restored object is not a Cold object. + |
+403 Forbidden + |
+
InvalidTagError + |
+An invalid tag is provided when configuring bucket tags. + |
+400 Bad Request + |
+
NoSuchTagSet + |
+The specified bucket is not configured with a tag. + |
+404 Not Found + |
+
After you call an API in an instance of the ObsClient class, a common result object will be returned if no exception is thrown. The following table lists the fields of the object:
+ +Parameter + |
+Type + |
+Description + |
+|
|---|---|---|---|
CommonMsg + |
+Object + |
+Common information generated after the API is called, including HTTP status code and error code. + |
+|
- + |
+Status + |
+Number + |
+HTTP status code. If the value is smaller than 300, the operation succeeds. Otherwise, the operation fails. + |
+
Code + |
+String + |
+Error code returned by the OBS server. If Status is smaller than 300, the value is null. + |
+|
Message + |
+String + |
+Error description returned by the OBS server. If Status is smaller than 300, the value is null. + |
+|
HostId + |
+String + |
+Requested Server ID. If Status is smaller than 300, the value is null. + |
+|
RequestId + |
+String + |
+Request ID returned by the OBS server + |
+|
Id2 + |
+String + |
+Request ID2 returned by the OBS server + |
+|
Indicator + |
+String + |
+Detailed error code returned by the OBS server. If Status is smaller than 300, the value is null. + |
+|
InterfaceResult + |
+Object + |
+Result data generated after the operation is successful. If Status is greater than 300, the value is null. + |
+|
- + |
+RequestId + |
+String + |
+Request ID returned by the OBS server. + |
+
Id2 + |
+String + |
+Request ID2 returned by the OBS server + |
+|
Other fields + |
+For details, see the Response area in the corresponding section. + |
+||
Sample code:
+// Import the OBS library.
+// Use npm to install the client.
+var ObsClient = require('esdk-obs-nodejs');
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+
+// Create an instance of ObsClient.
+const obsClient = new ObsClient({
+ //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.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+
+ server : 'https://your-endpoint'
+});
+
+// Call APIs to perform operations, such as downloading an object.
+obsClient.getObject({
+ Bucket : 'bucketname',
+ Key : 'objectname',
+}, (err, result) => {
+ if(!err){
+ if(result.CommonMsg.Status < 300){
+ // Obtain RequestId.
+ console.log('RequestId-->' + result.InterfaceResult.RequestId);
+ // Obtain other parameters.
+ console.log('Content-->' + result.InterfaceResult.Content.toString());
+ }else{
+ // Obtain Code and Message.
+ console.log('Code-->' + result.CommonMsg.Code);
+ console.log('Message-->' + result.CommonMsg.Message);
+ }
+ }
+});
+OBS Node.js SDK provides the logging function based on Log4js. You can call ObsClient.initLog to enable and configure logging. The sample code is as follows:
+obsClient.initLog({
+ name: 'test', // Log name
+file_full_path:'./logs/OBS-SDK.log', //Set the path to the log file.
+max_log_size:20480, //Set the size of the log file, in bytes.
+backups:10, //Set the maximum number of log files that can be stored.
+level:'warn', //Set the log level.
+log_to_console:true //Set whether to print the log to Console.
+});
+
The SDK log format is: Log time|log level|invoked interface|log content. The following are examples:
+2017/10/12 10:21:05 666|INFO |ListBuckets|enter ListBuckets... +2017/10/12 10:21:05 672|INFO |ListBuckets|prepare request parameters ok,then Send request to service start +2017/10/12 10:21:05 715|INFO |ListBuckets|2017-10-12 10:21:05|http cost 34 ms|0| +2017/10/12 10:21:05 716|INFO |ListBuckets|get response start, statusCode:200+
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 debug logs and the least information in error logs.
+The following describes each log level in detail.
+Problem: When OBS Node.js SDK is used for secondary development, an error message was displayed indicating that a module was missing, for example, "Cannot find module 'xml2js'".
+Solution:
+Problem: If a "connect ETIMEDOUT" error occurred when calling an API, the possible cause was that the service address (endpoint) was incorrect or the network was disconnected.
+Solution:
+Problem: The HTTP status code obtained from CommonMsg.Status was 403, and the OBS server-side error code obtained from CommonMsg.Code was SignatureDoesNotMatch.
+Solution:
+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.
+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 + |
+File Name Extension + |
+Content-Type + |
+
|---|---|---|---|
.* (binary stream, unknown file type) + |
+application/octet-stream + |
+.7z + |
+application/x-7z-compressed + |
+
.001 + |
+application/x-001 + |
+.301 + |
+application/x-301 + |
+
.323 + |
+text/h323 + |
+.906 + |
+application/x-906 + |
+
.907 + |
+drawing/907 + |
+.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 + |
+
.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 + |
+
.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 + |
+.dot + |
+application/msword + |
+
.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 + |
+
.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 + |
+.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 + |
+application/pdf + |
+||
.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 + |
+
.ppa + |
+application/vnd.ms-powerpoint + |
+.ppm + |
+application/x-ppm + |
+
.pps + |
+application/vnd.ms-powerpoint + |
+.ppt + |
+application/vnd.ms-powerpoint + |
+
.ppt + |
+application/x-ppt + |
+.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 + |
+.sit + |
+application/x-stuffit + |
+
.slb + |
+application/x-slb + |
+.sld + |
+application/x-sld + |
+
.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 + |
+text/xml + |
+
.swf + |
+application/x-shockwave-flash + |
+.tdf + |
+application/x-tdf + |
+
.tg4 + |
+application/x-tg4 + |
+.tga + |
+application/x-tga + |
+
.tif + |
+image/tiff + |
+.tiff + |
+image/tiff + |
+
.ttf + |
+font/otf + |
+.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 + |
+
.xdp + |
+application/vnd.adobe.xdp + |
+.xdr + |
+text/xml + |
+
.xfd + |
+application/vnd.adobe.xfd + |
+.xfdf + |
+application/vnd.adobe.xfdf + |
+
.xhtml + |
+text/html + |
+.xlsx + |
+application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + |
+
.xls + |
+application/x-xls + |
+.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_b + |
+application/x-x_b + |
+
.sis + |
+application/vnd.symbian.install + |
+.sisx + |
+application/vnd.symbian.install + |
+
.x_t + |
+application/x-x_t + |
+.ipa + |
+application/vnd.iphone + |
+
.apk + |
+application/vnd.android.package-archive + |
+.xap + |
+application/x-silverlight-app + |
+
.zip + |
+application/zip + |
+.rar + |
+application/x-rar-compressed + |
+
Release Date + |
+What's New + |
+
|---|---|
2025-11-20 + |
+This is the second official release. +Modified the following section: +Modified the description of the is_cname parameter in Configuring an Instance of ObsClient. + |
+
2025-06-30 + |
+This is the first official release. + |
+
To upload a large file, multipart upload is recommended. Multipart upload is applicable to many scenarios. Below are some examples.
+Multipart upload consists of three phases:
+ + +// Import the OBS library.
+// Use npm to install the client.
+const ObsClient = require('esdk-obs-nodejs');
+// Use the source code to install the client.
+// var ObsClient = require('./lib/obs');
+const fs = require('fs');
+
+// Create an ObsClient instance.
+var obsClient = new ObsClient({
+ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage.
+ // Obtain an AK/SK pair on the management console.
+ access_key_id: process.env.ACCESS_KEY_ID,
+ secret_access_key: process.env.SECRET_ACCESS_KEY,
+ // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways.
+ // security_token: process.env.SECURITY_TOKEN,
+ // Enter the endpoint of the region where the bucket is located.
+ server: "https://your-endpoint"
+});
+
+// Specify the bucket name.
+const Bucket = 'bucketname'
+// Specify an object (example/objectname in this example).
+const Key = 'objectname'
+
+// Specify the part size.
+const DEFAULT_PART_SIZE = 9 * 1024 * 1024;
+// Set the number of concurrent parts to 20.
+const CONCURRENCY = 20
+
+// Prepare multipart upload parameters.
+const preparePartParams = (Bucket, Key, UploadId) => (sampleFile, partSize = DEFAULT_PART_SIZE) => {
+ try {
+ const fileSize = fs.lstatSync(sampleFile).size;
+ const partCount = fileSize % partSize === 0 ? Math.floor(fileSize / partSize) : Math.floor(fileSize / partSize) + 1;
+
+ const uploadPartParams = [];
+ // Specify the concurrent upload.
+ for (let i = 0; i < partCount; i++) {
+ // Start position of parts in the file
+ let Offset = i * partSize;
+ // Part size
+ let currPartSize = (i + 1 === partCount) ? fileSize - Offset : partSize;
+ // Part number
+ let PartNumber = i + 1;
+ uploadPartParams.push({
+ Bucket,
+ Key,
+ PartNumber,
+ UploadId,
+ Offset,
+ SourceFile: sampleFile,
+ PartSize: currPartSize,
+ });
+ };
+
+ return ({ uploadPartParams, fileSize });
+ } catch (error) {
+ console.log(error)
+ };
+};
+
+
+/**
+ * uploadSuccessSize: Size of the parts that have been uploaded
+ * uploadSuccessCount: Number of the parts that have been uploaded
+ * concurrency: Current concurrency
+ */
+let uploadSuccessSize = 0;
+let uploadSuccessCount = 0;
+let concurrency = 0
+
+const parts = [];
+
+// Upload parts.
+const uploadPart = (uploadPartParam, otherUploadPartInfo) => {
+ const partCount = otherUploadPartInfo.partCount;
+ const fileSize = otherUploadPartInfo.fileSize;
+ concurrency++;
+ return obsClient
+ .uploadPart(uploadPartParam)
+ .then(result => {
+ const { PartNumber, PartSize } = uploadPartParam;
+ if (result.CommonMsg.Status < 300) {
+ uploadSuccessCount++;
+ uploadSuccessSize += PartSize;
+ // Print the upload progress.
+ console.log(`the current concurrent count is ${concurrency} | uploaded segment: ${uploadSuccessCount}/${partCount}. the progress is ${((uploadSuccessSize / fileSize) * 100).toFixed(2)}% | the partNumber ${PartNumber} upload succeeded.`);
+ parts.push({ PartNumber, ETag: result.InterfaceResult.ETag });
+ } else {
+ console.log(result.CommonMsg.Code, parts);
+ };
+ concurrency--;
+ }).catch(function (err) {
+ console.log(err);
+ throw err;
+ })
+};
+
+// Multipart upload
+const uploadFile = (sourceFile) => {
+ // Initiate the multipart upload task.
+ obsClient.initiateMultipartUpload({
+ Bucket,
+ Key
+ }).then(res => {
+ const Status = res.CommonMsg.Status;
+ const UploadId = res.InterfaceResult.UploadId;
+
+ if (typeof Status === 'number' && Status > 300) {
+ console.log(`initiateMultipartUpload failed! Status:${Status}`);
+ return;
+ };
+
+ const partParams = preparePartParams(Bucket, Key, UploadId)(sourceFile);
+ const uploadPartParams = partParams.uploadPartParams;
+ const fileSize = partParams.fileSize;
+ const partCount = uploadPartParams.length;
+ const otherUploadPartInfo = { fileSize, partCount };
+
+ // Call the parallel upload function.
+ parallelFunc(uploadPartParams, (param) => uploadPart(param, otherUploadPartInfo), CONCURRENCY)
+ .then(() => {
+ // Assemble parts.
+ obsClient.completeMultipartUpload({
+ Bucket,
+ Key,
+ UploadId,
+ Parts: parts.sort((a, b) => a.PartNumber - b.PartNumber)
+ }, (err, result) => {
+ if (err) {
+ console.log('Error-->' + err);
+ } else {
+ console.log('Status-->' + result.CommonMsg.Status);
+ };
+ });
+ });
+
+ }).catch(function (err) {
+ console.log(err)
+ });
+};
+
+
+/**
+ * Implement the parallel function execution.
+ * @param {Array} params Parameter array of the callback function
+ * @param {Promise} promiseFn Callback function
+ * @param {number} limit Number of parallel parts
+ */
+const parallelFunc = (params, promiseFn, limit) => {
+ return new Promise((resolve) => {
+ let concurrency = 0;
+ let finished = 0;
+ const count = params.length;
+ const run = (param) => {
+ concurrency++;
+ promiseFn(param)
+ .then(() => {
+ concurrency--;
+ drainQueue();
+ finished++;
+ if (finished === count) {
+ resolve();
+ };
+ });
+ };
+ const drainQueue = () => {
+ while (params.length > 0 && concurrency < limit) {
+ var param = params.shift();
+ run(param);
+ };
+ };
+ drainQueue();
+ });
+
+};
+
+uploadFile('localfile');
+
When uploading a large file in parts, you need to use the Offset and PartSize parameters to specify the start and end positions of each part in the file.
+
If the concurrency value is too great, timeout may occur due to network instability. In such case, you need to reduce that value.
+This API initiates a multipart upload and returns a globally unique upload ID. You can use this upload ID in your subsequent requests for uploading, assembling, and listing parts. Initiating multipart upload tasks do not affect existing objects with the same names as the involved objects in those tasks. There can be more than one multipart upload for the same object. Each multipart upload initiation request can contain additional headers such as contentType, contentEncoding, and the headers for ACL and custom metadata. These headers are recorded in the multipart upload metadata. After the API for initiating a multipart upload is successfully called, an upload ID will be returned. This ID will be used in subsequent operations.
+ObsClient.initiateMultipartUpload(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
ACL + |
++ | +No + |
+Explanation: +An access control list (ACL) that can be pre-defined when creating a bucket. +Restrictions: +None +Value range: +See Table 2. +Default value: +private + |
+
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 object anotherPage.html in the same bucket: +WebsiteRedirectLocation:/anotherPage.html +The request is redirected to an external URL: +WebsiteRedirectLocation:http://www.example.com/ +OBS obtains the specified value from the header and stores it in the object metadata WebsiteRedirectLocation. +Value range: +None +Restrictions: +
Default value: +None + |
+
ContentType + |
+string + |
+No + |
+Explanation: +MIME type of the file 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. +Restrictions: +None +Value range: +See What Is Content-Type (MIME)? +Default value: +If you do not specify this parameter 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 this parameter. + |
+
StorageClass + |
++ | +No + |
+Explanation: +Object storage class. If this parameter is not specified, the object inherits the storage class of its bucket. +Restrictions: +None +Value range: +See Table 3. +Default value: +STANDARD + |
+
Metadata + |
+object + |
+No + |
+Explanation: +Custom metadata of the object to be uploaded. You can add a header starting with x-obs-meta- in the request to define metadata. The custom metadata will be returned in the response when you retrieve the object or query the object metadata. +Restrictions: +
Value range: +None +Default value: +None + |
+
GrantRead + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can read the current object and obtain its metadata. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantReadAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantWriteAcp + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the current object. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
GrantFullControl + |
+string + |
+No + |
+Explanation: +ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can read the current object, obtain its metadata, and obtain and modify its ACL. +Restrictions: +Use commas (,) to separate multiple accounts. +Value range: +To obtain the account ID, see How Do I Get My Account ID and User ID? +Default value: +None + |
+
Expires + |
+number + |
+No + |
+Explanation: +Expiration time of the object (calculated from the latest modification time of the object). Expired objects are automatically deleted. +Restrictions: +
Value range: +1 to (263 - 1), in days +Default value: +None + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +Currently, only KMS is supported. +Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.AclPrivate + |
+private + |
+Private read and write +A bucket or object can only be accessed by its owner. + |
+
ObsClient.enums.AclPublicRead + |
+public-read + |
+Public read and private write +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadWrite + |
+public-read-write + |
+Public read and write +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. +If this permission is granted on an object, everyone can obtain the content and metadata of the object. + |
+
ObsClient.enums.AclPublicReadDelivered + |
+public-read-delivered + |
+Public read on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket. + NOTE:
+AclPublicReadDelivered does not apply to objects. + |
+
ObsClient.enums.AclPublicReadWriteDelivered + |
+public-read-write-delivered + |
+Public read and write on a bucket as well as the objects in the bucket. +If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket 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 objects in the bucket. + NOTE:
+AclPublicReadWriteDelivered does not apply to objects. + |
+
ObsClient.enums.AclBucketOwnerFullControl + |
+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 of any other user, the bucket owner does not have the permissions on your object. After you grant this policy 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 the bucket-owner-full-control policy for object x, user B then has the control over object x. + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 5. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 7. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Bucket + |
+string + |
+Explanation: +Name of the bucket involved in the multipart upload. + |
+
Key + |
+string + |
+Explanation: +Object name in the multipart upload. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
UploadId + |
+string + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
This example initiates a multipart upload for object example/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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function initiateMultipartUpload() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object (example/objectname in this example). + Key: "example/objectname", + }; + // Initiate the multipart upload. + const result = await obsClient.initiateMultipartUpload(params); + if (result.CommonMsg.Status <= 300) { + console.log("Initiate multipart upload successfully with bucket(%s) and object(%s)!", params.Bucket, params.Key); + console.log("RequestId: %s", result.CommonMsg.RequestId); + // A globally unique identifier of the multipart upload task, which will be used in uploading and assembling parts. + console.log("UploadId: %s", result.InterfaceResult.UploadId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +initiateMultipartUpload(); + |
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.
+When uploading a part, you must specify its upload ID and part number. You can select any part number between 1 and 10000. A part number uniquely identifies a part and its location in the object you are uploading. If the number of an uploaded part is used to upload a new part, the uploaded part will be overwritten. Whenever you upload a part, OBS returns the ETag header in the response. For each part upload, you must record the part number and the ETag value. These values are required in subsequent requests to complete a multipart upload.
+ObsClient.uploadPart(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
PartNumber + |
+number + |
+Yes + |
+Explanation: +Part number. +Restrictions: +None +Value range: +An integer ranging from 1 to 10000. +Default value: +None + |
+
UploadId + |
+string + |
+Yes + |
+Explanation: +Multipart upload ID, which is generated by initiating a multipart upload. +Restrictions: +None +Value range: +The value must contain 32 characters, +for example, 000001648453845DBB78F2340DD460D8. +Default value: +None + |
+
ContentMD5 + |
+string + |
+No + |
+Explanation: +Base64-encoded MD5 value of the data to be uploaded. It is used for the OBS server to verify data integrity. +Restrictions: +Base64-encoded, 128-bit MD5 value of the request body. +Value range: +Base64-encoded, 128-bit MD5 value of the request body calculated based on the RFC 1864 standard. +Example: n58IG6hfM7vqI4K0vnWpog== +Default value: +None + |
+
Body + |
+string | stream.Readable + |
+No + |
+Explanation: +Data stream of the object to be uploaded. +Restrictions: +The content size in a single upload ranges from 0 to 5 GB. +Value range: +None +Default value: +None + |
+
SourceFile + |
+string + |
+No + |
+Explanation: +Source file path of the object to be uploaded +Restrictions: +
Value range: +None +Default value: +None + |
+
Offset + |
+number + |
+No + |
+Explanation: +Start offset of a part in the source file. +Restrictions: +Offset, PartSize, and SourceFile can be used together to specify part of the source file to upload. +Value range: +A non-negative integer smaller than the size of the object to be uploaded, in bytes +Default value: +0 + |
+
PartSize + |
+number + |
+No + |
+Explanation: +Part size. +Restrictions: +Offset, PartSize, and SourceFile can be used together to specify part of the source file to upload. +Value range: +The value ranges from 100 KB to 5 GB, in bytes. +Default value: +102400 + |
+
SseKms + |
+string + |
+Yes when SSE-KMS is used + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. +Restrictions: +Currently, only KMS is supported. +Value range: +kms +Default value: +None + |
+
SseKmsKey + |
+string + |
+No + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. +Restrictions: +Valid value formats are as follows: +
In the preceding formats: +
Value range: +None +Default value: +
|
+
SseC + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +SSE-C is used for encrypting objects on the server side. +Restrictions: +Only AES256 is supported. +Value range: +AES256 +Default value: +None + |
+
SseCKey + |
+string + |
+Yes when SSE-C is used + |
+Explanation: +Key used for encrypting the object when SSE-C is used +Restrictions: +A Base64-encoded, 256-bit value, for example, K7QkYpBkM5+hca27fsNkUnNVaobncnLht/rCB2o/9Cw= +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. The ETag is a unique identifier for the object's contents, used to determine if the object has been updated. For example, if the ETag value is A when an object is uploaded and becomes B when the object is downloaded, this indicates the contents of the object were changed. The ETag reflects changes of an object, not of the 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. + |
+
This example uploads a part to bucket examplebucket in a specified multipart upload (uploadId) of object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function uploadPart() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify the object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the ID of the multipart upload. + UploadId: "0000000xxxxxxxx", + // Specify the part number (1 in this example) of the part to upload. The part number is an integer ranging from 1 to 10000. + PartNumber: 1, + // Specify the source file path of the part to upload (localfile in this example). + SourceFile: "localfile", + // Specify the part size (5 MB in this example), in bytes. + PartSize: 5 * 1024 * 1024, + // Specify the offset of the part (0 in this example). + Offset: 0 + }; + // Upload the part. + const result = await obsClient.uploadPart(params); + if (result.CommonMsg.Status <= 300) { + console.log("Upload part(%d) successful with bucket(%s) and object(%s)!", params.PartNumber, params.Bucket, params.Key); + console.log("RequestId: %s", result.CommonMsg.RequestId); + console.log("ETag: %s", result.InterfaceResult.ETag); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +uploadPart(); + |
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 in the same way the information in a regular object upload is processed. In the case of assembling parts concurrently, the Last Write Wins strategy applies, 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 arranges parts in ascending order by part number. If any object metadata is provided during the initiation of the multipart upload, OBS will associate this metadata with the object. When the multipart upload is complete, the individual parts will no longer exist. A part assembling request must contain the upload ID, part numbers, and ETag values. OBS responses include the ETag that uniquely identifies the object data. This ETag is not required to be the MD5 hash value of the object data.
+ObsClient.completeMultipartUpload(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
UploadId + |
+string + |
+Yes + |
+Explanation: +Multipart upload ID, which is generated by initiating a multipart upload. +Restrictions: +None +Value range: +The value must contain 32 characters, for example, 000001648453845DBB78F2340DD460D8. +Default value: +None + |
+
Parts + |
+Part[] + |
+Yes + |
+Explanation: +List of parts to be assembled. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
PartNumber + |
+number + |
+Explanation: +Part number. +Restrictions: +None +Value range: +An integer ranging from 1 to 10000. +Default value: +None + |
+
ETag + |
+string + |
+Explanation: +ETag of a part. It is calculated by encoding the 128-bit MD5 value of the part using Base64. +Restrictions: +ETag (MD5 value of the part data) can be obtained from the response returned by the API for uploading a part. +Value range: +The value must contain 32 characters. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an assembled object calculated based on the ETag of each part. The ETag is a unique identifier for the object's contents, used to determine if the object has been updated. For example, if the ETag value is A when an object is uploaded and becomes B when the object is downloaded, this indicates the contents of the object were changed. The ETag reflects changes of an object, not of the 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. + |
+
Bucket + |
+string + |
+Explanation: +Name of the bucket in which parts are assembled + |
+
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
Location + |
+string + |
+Explanation: +URL of the object obtained from assembling the parts. + |
+
VersionId + |
+string + |
+Explanation: +Version ID of the object obtained from assembling the parts. If versioning is enabled for the bucket, the object version ID will be returned. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
EncodingType + |
+string + |
+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. + |
+
This example assembles the uploaded parts to complete multipart upload 00000188677110424014075CC4A77xxx of object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function completeMultipartUpload() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the multipart upload ID (00000188677110424014075CC4A77xxx in this example). + UploadId: "00000188677110424014075CC4A77xxx", +// Specify the list of parts to be assembled. The parts must be sorted by part number in ascending order, and the parts can be inconsecutive. + Parts: [ + { PartNumber: 1, ETag: "etag1" }, + { PartNumber: 2, ETag: "etag2" }, + { PartNumber: 3, ETag: "etag3" }, + ] + }; + // Assemble parts. + const result = await obsClient.completeMultipartUpload(params); + if (result.CommonMsg.Status <= 300) { + console.log("Complete multipart upload successful with bucket(%s) and object(%s)!", params.Bucket, params.Key); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +completeMultipartUpload(); + |
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. For each listing request, OBS can list a maximum of 1,000 uploaded parts. If more than 1,000 parts were uploaded for a multipart upload, you need to send more than one request to list all uploaded parts. Assembled parts will not be listed.
+ObsClient.listParts(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
UploadId + |
+string + |
+Yes + |
+Explanation: +Multipart upload ID, which is generated by initiating a multipart upload. +Restrictions: +None +Value range: +The value must contain 32 characters, for example, 000001648453845DBB78F2340DD460D8. +Default value: +None + |
+
PartNumberMarker + |
+number + |
+No + |
+Explanation: +Part number the listing starts from. +Restrictions: +None +Restrictions: +OBS only lists parts with greater numbers than that specified by this parameter. +Default value: +None + |
+
MaxParts + |
+number + |
+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 + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Bucket + |
+string + |
+Explanation: +Bucket name + |
+
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
UploadId + |
+string + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. + |
+
Initiator + |
++ | +Explanation: +Initiator of the multipart upload. For details, see Table 6. + |
+
Owner + |
++ | +Explanation: +Owner of the multipart upload, which is consistent with an initiator. For details, see Table 7. + |
+
StorageClass + |
++ | +Explanation: +Storage class of the object obtained from assembling parts. For details about storage classes, see Table 8. + |
+
PartNumberMarker + |
+number + |
+Explanation: +Part number the listing begins from, which is consistent with that specified in the request. + |
+
NextPartNumberMarker + |
+number + |
+Explanation: +Part number to start with for the next part listing request. This parameter is returned if some parts were not listed. You can set PartNumberMarker to this value in the next request to list the remaining parts. + |
+
MaxParts + |
+number + |
+Explanation: +Maximum number of parts that can be listed per page, which is consistent with that specified in the request. + |
+
IsTruncated + |
+boolean + |
+Explanation: +Whether all results are returned in the response. +Value range: +
|
+
Parts + |
+Part[] + |
+Explanation: +List of uploaded parts. For details, see Table 9. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Account (domain) ID of the initiator +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 initiator +Restrictions: +The account name can contain 6 to 32 characters and must start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
PartNumber + |
+number + |
+Explanation: +Part number + |
+
LastModified + |
+string + |
+Explanation: +Time when a part was last modified, in UTC + |
+
ETag + |
+string + |
+Explanation: +ETag of a part. It is calculated by encoding the 128-bit MD5 value of the part using Base64. + |
+
Size + |
+number + |
+Explanation: +Size of the space occupied by a part + |
+
This example lists the parts that have been uploaded for a multipart 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 +63 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listParts() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the multipart upload ID (00000188677110424014075CC4A77xxx in this example). + UploadId: "00000188677110424014075CC4A77xxx", + // Specify the maximum number of objects to be returned in alphabetic order. The default value is 1000. 100 is used in this example. + MaxKeys: 100, + }; + // List uploaded parts. + const result = await obsClient.listParts(params); + if (result.CommonMsg.Status <= 300) { + console.log("List part successful with bucket(%s) and object(%s)!", params.Bucket, params.Key); + console.log('RequestId: %s', result.CommonMsg.RequestId); + console.log('Bucket: %s', result.InterfaceResult.Bucket); + console.log('Key: %s', result.InterfaceResult.Key); + console.log('UploadId: %s', result.InterfaceResult.UploadId); + console.log('PartNumberMarker: %s', result.InterfaceResult.PartNumberMarker); + console.log('NextPartNumberMarker: %s', result.InterfaceResult.NextPartNumberMarker); + console.log('MaxParts: %s', result.InterfaceResult.MaxParts); + console.log('IsTruncated: %s', result.InterfaceResult.IsTruncated); + console.log('StorageClass: %s', result.InterfaceResult.StorageClass); + console.log('Initiator[ID]: %s', result.InterfaceResult.Initiator['ID']); + console.log('Owner[ID]: %s', result.InterfaceResult.Owner['ID']); + for (let i = 0; i < result.InterfaceResult.Parts.length; i++) { + const part = result.InterfaceResult.Parts[i]; + console.log("Part[%d]-ETag:%s, PartNumber:%d, LastModified:%s, Size:%d", + i, part.PartNumber, part.LastModified, part.ETag, part.Size); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listParts(); + |
This API lists multipart uploads that have been initiated but not completed or cancelled.
+You can list all the multipart uploads that are not assembled or aborted in a bucket. Each request can return up to 1,000 multipart uploads. If a bucket contains more than 1,000 multipart uploads, InterfaceResult.IsTruncated in the response is true, indicating not all uploads were listed. In such case, you can use InterfaceResult.NextKeyMarker and InterfaceResult.NextUploadIdMarker to obtain the start position for the next listing.
+ObsClient.listMultipartUploads(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +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 that contain logs/day1, logs/day2, or logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all multipart uploads in the bucket will be returned. +Restrictions: +The value can contain 1 to 1,024 characters. +Value range: +None +Default value: +None + |
+
MaxUploads + |
+number + |
+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 + |
+
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 placed separately into another CommonPrefixes with bbcd as the prefix. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
KeyMarker + |
+string + |
+No + |
+Explanation: +Object name to start with when listing multipart uploads +Restrictions: +None +Value range: +The value of NextKeyMarker in the response body of the last request. +Default value: +None + |
+
UploadIdMarker + |
+string + |
+No + |
+Explanation: +Upload ID to start with when listing multipart uploads +Restrictions: +This parameter is valid only when used with KeyMarker. If both parameters are specified, 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 + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
Bucket + |
+string + |
+Explanation: +Bucket name + |
+
KeyMarker + |
+string + |
+Explanation: +Object name to start with when listing multipart uploads. This parameter corresponds to KeyMarker in the request. + |
+
UploadIdMarker + |
+string + |
+Explanation: +Upload ID to start with when listing multipart uploads. This parameter corresponds to UploadIdMarker in the request. + |
+
NextKeyMarker + |
+string + |
+Explanation: +Object name to start with for the next multipart upload listing request. This parameter is returned if some results were not returned. You can set KeyMarker in the next request to the returned value to list the remaining results. + |
+
NextUploadIdMarker + |
+string + |
+Explanation: +Upload ID to start with for the next multipart upload listing request. This parameter is used together with NextKeyMarker. This parameter is returned if some listing results were not returned. You can set UploadIdMarker of the next request to the returned value to list the remaining multipart uploads. + |
+
MaxUploads + |
+number + |
+Explanation: +Maximum number of multipart uploads that can be listed. This parameter corresponds to MaxUploads in the request. + |
+
IsTruncated + |
+boolean + |
+Explanation: +Whether all results are returned in the response. +Value range: +
|
+
Prefix + |
+string + |
+Explanation: +Object name prefix in multipart uploads. This parameter corresponds to Prefix in the request. It defines the 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 that contain logs/day1, logs/day2, or logs/day3 will be returned. If this parameter is left blank and there are no other filtering criteria, all multipart uploads in the bucket will be returned. + |
+
Delimiter + |
+string + |
+Explanation: +Used to group object names involved in multipart uploads. This parameter corresponds to Delimiter 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 placed separately into another CommonPrefixes with bbcd as the prefix. + |
+
Uploads + |
+Upload[] + |
+Explanation: +List of multipart uploads. For details, see Table 6. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
Key + |
+string + |
+Explanation: +Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. + |
+
UploadId + |
+string + |
+Explanation: +Multipart upload ID, for example, 000001648453845DBB78F2340DD460D8. + |
+
Initiator + |
++ | +Explanation: +Initiator of the multipart upload. For details, see Table 7. + |
+
Owner + |
++ | +Explanation: +Account ID of the object owner. For details, see Table 8. + |
+
StorageClass + |
++ | +Explanation: +Storage class of the object involved in the multipart upload. For details about the storage classes, see Table 9. + |
+
Initiated + |
+string + |
+Explanation: +Time when the multipart upload was initiated + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+Explanation: +Account (domain) ID of the initiator +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 initiator +Restrictions: +The account name can contain 6 to 32 characters and must start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. +Default value: +None + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
ID + |
+string + |
+Yes if used as a request parameter + |
+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 +Default value: +None + |
+
Constant + |
+Default Value + |
+Description + |
+
|---|---|---|
ObsClient.enums.StorageClassStandard + |
+STANDARD + |
+Standard storage class. +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. + |
+
ObsClient.enums.StorageClassWarm + |
+WARM + |
+Warm storage class. +Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. + |
+
ObsClient.enums.StorageClassCold + |
+COLD + |
+Cold storage class. +Used for storing rarely accessed (once a year) data. + |
+
This example lists all multipart uploads for bucket examplebucket that have been initiated but not completed or aborted.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function listMultipartUploads() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the maximum number of multipart uploads that can be listed. 10 is used in this example. + MaxUploads: 10 + }; + // List multipart uploads. + const result = await obsClient.listMultipartUploads(params); + if (result.CommonMsg.Status <= 300) { + console.log("List multipart uploads successful with bucket(%s) !", params.Bucket); + console.log("RequestId: %s", result.CommonMsg.RequestId); + for (let i = 0; i < output.Uploads.length; i++) { + const upload = output.Uploads[i]; + console.log("Upload[%d]-OwnerId:%s, UploadId:%s, Key:%s, Initiated:%s", + i, upload.Owner.ID, upload.UploadId, upload.Key, upload.Initiated); + }; + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +listMultipartUploads(); + |
This API uploads a part for a specified multipart upload by copying data to a specified bucket.
+After initiating a multipart upload task, you can add parts for this task by copying part or all of an existing object in OBS.
+Assume that you copy a source object and save it as part1. If there is already an existing part called part1, the new part1 will overwrite the existing part1. Then, only the new part1 can be listed. The old part1 is deleted. To prevent accidental deletion, ensure there is no existing object with the same name as the part involved when using this API. The source object remains unchanged during the copy process.
+ObsClient.copyPart(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Destination bucket name. +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
PartNumber + |
+number + |
+Yes + |
+Explanation: +Part number. +Restrictions: +None +Value range: +Value range: 1–10000 +Default value: +None + |
+
UploadId + |
+string + |
+Yes + |
+Explanation: +Multipart upload ID, which is generated by initiating a multipart upload. +Restrictions: +None +Value range: +The value must contain 32 characters, for example, 000001648453845DBB78F2340DD460D8. +Default value: +None + |
+
CopySource + |
+string + |
+Yes + |
+Explanation: +Names of the source bucket and object. If the source object has multiple versions, the versionId parameter is used to specify the desired version. +Example: source_bucket/sourceObject?versionId=G001117FCE89978B0000401205D5DC9A +Restrictions: +Full-width characters and percent signs (%) must be URL-encoded. +Value range: +None +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 3. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 4. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 5. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server + |
+
ETag + |
+string + |
+Explanation: +Base64-encoded, 128-bit MD5 value of an object. The ETag is a unique identifier for the object's contents, used to determine if the object has been updated. For example, if the ETag value is A when an object is uploaded and becomes B when the object is downloaded, this indicates the contents of the object were changed. The ETag reflects changes of an object, not of the 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. + |
+
LastModified + |
+string + |
+Explanation: +Time when a part was last modified, in UTC + |
+
PartNumber + |
+number + |
+Explanation: +Part number. + |
+
SseKms + |
+string + |
+Explanation: +SSE-KMS is used for encrypting objects on the server side. + |
+
SseKmsKey + |
+string + |
+Explanation: +ID of the KMS master key when SSE-KMS is used. + |
+
SseC + |
+string + |
+Explanation: +SSE-C is used for encrypting objects on the server side. + |
+
SseCKeyMd5 + |
+string + |
+Explanation: +MD5 value of the key used for encrypting objects when SSE-C is used. This value is used to check whether any error occurs during the transmission of the key. +Restrictions: +Base64-encoded MD5 value of the key, for example, 4XvB3tbNTN+tIEVa0/fGaQ== + |
+
This example copies a part from object example/sourceobjectname in bucket sourcebucketname to object example/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 | // Import the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function copyPart() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the names of the source bucket (sourcebucketname in this example) and source object (example/sourceobjectname in this example). + CopySource: "sourcebucketname/example/sourceobjectname", + // Specify the part number (1 in this example). + PartNumber: 1, + // Specify the multipart upload ID (00000188677110424014075CC4A77xxx in this example). + UploadId: "00000188677110424014075CC4A77xxx", + }; + // Copy the part. + const result = await obsClient.copyPart(params); + if (result.CommonMsg.Status <= 300) { + console.log("Complete multipart upload successful with bucket(%s) and object(%s)!", params.Bucket, params.Key); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +copyPart(); + |
This API aborts a multipart upload by specifying its ID.
+After a multipart upload is aborted, its upload ID cannot be used to upload any part. And the space occupied by all uploaded parts will be freed up. If any parts are being uploaded when you abort the upload, they may or may not be uploaded successfully. To free up the space occupied by all uploaded parts, you must abort the multipart upload after all parts have been uploaded.
+ObsClient.abortMultipartUpload(params)+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
input + |
++ | +Yes + |
+Explanation: +Input parameters in the request for aborting a multipart upload. For details, see Table 2. + |
+
Parameter + |
+Type + |
+Mandatory (Yes/No) + |
+Description + |
+
|---|---|---|---|
Bucket + |
+string + |
+Yes + |
+Explanation: +Bucket name +Restrictions: +
Value range: +The value can contain 3 to 63 characters. +Default value: +None + |
+
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 of the object that does not contain the bucket name. +Restrictions: +None +Value range: +The value can contain 1 to 1,024 characters. +Default value: +None + |
+
UploadId + |
+string + |
+Yes + |
+Explanation: +Multipart upload ID, which is generated by initiating a multipart upload. +Restrictions: +None +Value range: +The value must contain 32 characters, for example, 000001648453845DBB78F2340DD460D8. +Default value: +None + |
+
Type + |
+Description + |
+
|---|---|
|
+ NOTE:
+This API returns a Promise response, which requires the Promise or async/await syntax. + |
+Explanation: +Returned results. For details, see Table 4. + |
+
Parameter + |
+Type + |
+Description + |
+
|---|---|---|
CommonMsg + |
++ | +Explanation: +Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 5. + |
+
InterfaceResult + |
++ | +Explanation: +Results outputted for a successful call. For details, see Table 6. +Restrictions: +This parameter is not included if the value of Status is greater than 300. + |
+
Parameter + |
+Type + |
+Description + |
+
Status + |
+number + |
+Explanation: +HTTP status code returned by the OBS server. +Value range: +A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). + |
+
Code + |
+string + |
+Explanation: +Error code returned by the OBS server. + |
+
Message + |
+string + |
+Explanation: +Error description returned by the OBS server. + |
+
HostId + |
+string + |
+Explanation: +Request server ID returned by the OBS server. + |
+
RequestId + |
+string + |
+Explanation: +Request ID returned by the OBS server. + |
+
Id2 + |
+string + |
+Explanation: +Request ID2 returned by the OBS server. + |
+
Indicator + |
+string + |
+Explanation: +Error code details returned by the OBS server. + |
+
This example aborts multipart upload 00000188677110424014075CC4A77xxx.
+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 the OBS library. +// Use npm to install the client. +const ObsClient = require("esdk-obs-nodejs"); +// Use the source code to install the client. +// var ObsClient = require('./lib/obs'); + +// Create an instance of ObsClient. +const obsClient = new ObsClient({ + // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. + // Obtain an AK/SK pair on the management console. + access_key_id: process.env.ACCESS_KEY_ID, + secret_access_key: process.env.SECRET_ACCESS_KEY, + // (Optional) If you use 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. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. + // security_token: process.env.SECURITY_TOKEN, + // Enter the endpoint of the region where the bucket is located. + server: "https://your-endpoint" +}); + +async function abortMultipartUpload() { + try { + const params = { + // Specify the bucket name. + Bucket: "examplebucket", + // Specify an object. example/objectname is used in this example. + Key: "example/objectname", + // Specify the multipart upload ID (00000188677110424014075CC4A77xxx in this example). + UploadId: "00000188677110424014075CC4A77xxx", + }; + // Abort the multipart upload. + const result = await obsClient.abortMultipartUpload(params); + if (result.CommonMsg.Status <= 300) { + console.log("Abort multipart upload successful!"); + console.log("RequestId: %s", result.CommonMsg.RequestId); + return; + }; + console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); + console.log("Status: %d", result.CommonMsg.Status); + console.log("Code: %s", result.CommonMsg.Code); + console.log("Message: %s", result.CommonMsg.Message); + console.log("RequestId: %s", result.CommonMsg.RequestId); + } catch (error) { + console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); + console.log(error); + }; +}; + +abortMultipartUpload(); + |