Download Object

This SDK method can be used to download an object from the bucket. The response will be in blob format. The Stratus reference used in the below code snippet is the component instance.

Expected responses with respect to Versioning status of the bucket:

  • If you do not pass the versionId, then you will get the latest object, along with the key you mention in the request.
  • If Versioning was enabled for a bucket, then disabled. By default, the principal first object will be returned. To ensure you download the latest version of this object, you need to pass the versionId param with the value “topVersion”.
  • To retrieve a specific version, use the versionId query parameter with a valid version as a value.

Parameters Used

Parameter Name Data Type Definition
key String Will hold the name of the object
options JSON Object
  • versionId: This is an optional String parameter. Will hold the unique version ID of the required object's version.
  • range: This is an optional String parameter. The byte range of the required object. Will be used to get a specific part of the object.
  • cached: This is an optional Boolean parameter.
    • Will be used to get cached version of the object
    • Will only accept two values: "true" or "false"
    • false will be the value, if this param is not used
    • true will be the value, if Caching is enabled for your bucket and you pass this param. In this case, the object will be retrieved from the cached domain.
  • signed: This is an optional Boolean parameter. The default value is "false". Will make an api call to get a signed url.
  • signedUrlFn:
    • This is an optional Function parameter.
    • This is a Callback function that will return a signedurl api respone given in server SDK (Java, Node.js, and Python) to download a file.
    • This function will only accept asynchronous functions and promises.
    • When this function is used, Catalyst will pass the cached url and expiry time to it as parameters which can be used to generate a signed url.
processCallback Function Callback function while downloading file

Download Object Using Object Name

The following SDK snippet will allow you to download an object from a bucket in Stratus using its key.

    
copy
const getObject = await bucket.getObject("key"); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Download a Particular Version of the Object

The following SDK snippet will allow you to download a particular version of the object from a bucket in Stratus using its key, and versionId.

    
copy
const options = { 'versionId': 'djkshr8374yiuhf48', // download a specific version of an object } const getObject = await bucket.getObject("key", options); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Download Object With Process Callback

The following SDK snippet will allow you to download a particular object from a bucket in Stratus with process callback options. This SDK is best used when you wish to perform an additional function like logging, rendering load/buffer screens, etc. alongside the download operation.

    
copy
// process callback while an object is being downloaded const processCallback = () => { // Function to execute while the object is being fetched console.log("Downloading Object"); } const options = { 'versionId': 'djkshr8374yiuhf48' } const getObject = await bucket.getObject("key", options, processCallback); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Example Response

    
copy
{ "status": 200, "content": {Blob Data}, "message": "OK" }

Possible Exceptions

  • 404: Object or Bucket Not Found
  • 416: Requested range not satisfiable

Download a Particular Part of the Object

In this section, we are going to go over an SDK method that will allow you to successfully download a required byte range of the object from Stratus to your local system. The Stratus reference used in the below code snippet is the component instance.

This method functions in a manner where the object is split into multiple byte ranges using the start and end bytes range of the object.

    
copy
const processCallback = () => { // Function to execute while the object is being fetched console.log("Downloading Object"); } const options = { 'range': '0-2000' // start and end range of the object in bytes } const getObject = await stratus.getObject("key", options, processCallback); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Example Response

    
copy
{ "status": 206, "content": {Blob Data}, "message": "PARTIAL_CONTENT" }

Download Object Using a Signed URL

Using Asynchronous Functions

    
copy
// Download Object Using Signed Url // Using Asynchronous Function const processCallback = () => { // Function to execute while the object is being fetched console.log("Downloading Object"); } const options = { 'range': '0-2000' // start and end range of the object in bytes, 'signed': true, // to declare we will be using signed url to getObject from bucket. 'signedUrlFn' : async (functionData) => { console.log("Data : " + functionData); // Function Logic return { "signed_url": "" //signed url } } } const getObject = await stratus.getObject("key", options, processCallback); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Using Promises

    
copy
// Using Promises const processCallback = () => { // Function to execute while the object is being fetched console.log("Downloading Object"); } const options = { 'range': '0-2000' // start and end range of the object in bytes, 'signed': true, // to declare we will be using signed url to getObject from bucket. 'signedUrlFn' : (functionData) => { return new Promise((resolve, reject) => { console.log("Data : " + functionData); // Function Logic resolve({ "signed_url" : "" }) }) } } const getObject = await stratus.getObject("key", options, processCallback); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Using SignedURL with Options

The following SDK method will allow you download an object using a signed URL, and to set an expiry time for the signed URL.

    
copy
// Download Object Using Signed Url and Expiry Time const processCallback = () => { // Function to execute while the object is being fetched console.log("Downloading Object"); } const options = { 'range': '0-2000' // start and end range of the object in bytes, 'signed': true, // to declare we will be using signed url to getObject from bucket. 'signedUrlFn' : async (functionData) => { console.log("Data : " + functionData); // Function Logic return { "signed_url": "" // Signed Url } }, "expiryInSeconds" : 3000 // In Seconds } const getObject = await stratus.getObject("key", options, processCallback); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Download a Cached Object Using Cached URL

The following SDK method will allow you to download a cached object using the Cached URL.

    
copy
// Cached URL const processCallback = () => { // Function to execute while the object is being fetched console.log("Downloading Object"); } const options = { 'range': '0-2000' // start and end range of the object in bytes, 'cached': true, // to declare we will be using cached url to getObject from bucket. } const getObject = await stratus.getObject("key", options, processCallback); const getObjectStart = getObject.start(); // to start the request const getObjectAbort = getObject.abort(); // to abort the request

Last Updated 2025-07-02 15:43:56 +0530 +0530