Get Object
Updated at:2025-11-03
Get object (Node.js only)
Simple object get
Users can load the object into a stream by using the following code.
-
Basic workflow
- Create a BosClient instance.
- Execute the getObject() command.
-
Example code
JavaScript1let range = '0-100'; 2client.getObject(<BucketName>, <Key>, range) 3 .then(function(response) { 4 let buffer = response.body; 5 });Plain Text1> **Note:** Setting `range` to 0-100 means only getting data from 0 to 100 bytes. You can use this function to implement segmented download and resumable download of files. If `range` is not set, the entire object will be obtained.
Download object to a specified path
Users can use the following code to directly download an object to a specified path.
-
Basic workflow
- Create a BosClient instance.
- Execute the client.getObject() operation.
- Download an object directly to a specified path.
-
Example code
JavaScript1let range = '0-100'; 2client.getObjectToFile(<bucketName>, <key>, <filePath>, range) 3 .then(function() { 4 // Download completed 5 });Plain Text1> **Note:** Setting `range` to 0-100 means only getting data from 0 to 100 bytes. You can use this function to implement segmented download and resumable download of files. If `range` is not set, the entire object will be obtained. filePath is the full path of the file, including the file name and type.
Obtain only ObjectMetadata
The getObjectMetadata() method retrieves only the ObjectMetadata, without obtaining the object itself.
-
Example code
JavaScript1client.getObjectMetadata(<BucketName>, <ObjectKey>) 2 .then(function(response) { 3 console.dir(response.http_headers); 4 });
