Upload Object

The SDK method listed in this section will allow you to upload objects to the bucket. The Stratus reference used in the below code snippet is the component instance.

If you do not have Versioning enabled for your object, and if Stratus gets multiple write requests for the same object, the object will be continuously overwritten. The latest upload of the object will be the only object that is stored.

However, with Versioning enabled, each upload will be considered a version of the object, and all of them will be stored in the bucket, each with a unique versionId.

Note: The following characters including space are not supported when you create a path or an object: double quote, both angular brackets, hashtag, backward slash and pipe symbol.

Parameters Used

Parameter Name Data Type Definition
key String A Mandatory parameter. Will hold the complete name of the object along with it's path.
File File | String A Mandatory parameter. The object that needs to be uploaded.
options JSON Object
  • overwrite: This is an optional String parameter.
    • If Versioning for your bucket is not enabled, then you need to use this option if you wish to overwrite a resource.
    • Default value: false
  • ttl: This is an optional String | Number parameter.
    • You can set Time-to-Live (ttl) in seconds for an object.
    • The value should be greater than or equal to 60 seconds.
  • type: This is an optional String parameter.
    • This paramater can be used to overwrite the content-type of the object.
    • If you do not pass this parameter, then by default the value of type will be application/octet-stream
  • meta: This is an optional JSON Object parameter. It is used to add the meta details of an object that is being uploaded to a bucket. Default value is an empty JSON object
processCallback Function Callback function while downloading file

Upload Object as File

The following SDk method will allow you to upload an object file to a bucket in Stratus.

    
copy
// Upload Object as File const file = document.getElementById("uploadedFiles").files[0] const putObject = await bucket.putObject("key", file); const putObjectStart = putObject.start(); // to start the request const putObjectAbort = putObject.abort(); // to abort the request

Upload Object as String

The following SDk method will allow you to upload a string object to a bucket in Stratus.

    
copy
// Upload Object as String const putObject = await bucket.putObject("key", "Content of the file"); const putObjectStart = putObject.start(); // to start the request const putObjectAbort = putObject.abort(); // to abort the request

Upload Object With Options

The following SDK method will allow you to upload any object to a bucket in Stratus. Using this SDK method you can implement the options parameter to provide type, overwrite, and ttl instructions.

    
copy
// Upload Object with options const options = { "overwrite": true, //To overwrite an existing object "ttl": 300, //After 300 seconds the object will be deleted from the bucket "type": "text/plain" // File type of the object being uploaded } const putObject = await bucket.putObject("key", "Content of the file", options); const putObjectStart = putObject.start(); // to start the request const putObjectAbort = putObject.abort(); // to abort the request

Upload Object With Process Callback

The following SDK snippet will allow you to upload a particular object to 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 upload operation.

    
copy
// Execute a function while object being uploaded const processCallback = () => { // Function to execute while the object is being uploaded console.log("Uploading Object"); } const options = { "overwrite": true, "ttl": 300, "type": "text/plain" } const putObject = await bucket.putObject("key", "Content of the file", options, processCallback); const putObjectStart = putObject.start(); // to start the request const putObjectAbort = putObject.abort(); // to abort the request

Upload Object With Its Meta Details

The following SDK snippet will allow you to upload a particular object along with its metadata to a bucket in Stratus.

    
copy
// Upload Object with meta const options = { "overwrite": true, "ttl": 300, "type": "text/plain" // File type of the uploading object "meta": { "object_meta_key" : "object_meta_value" } } const putObject = await bucket.putObject("key", "Content of the file", options); const putObjectStart = putObject.start(); // to start the request const putObjectAbort = putObject.abort(); // to abort the request

Example Response

    
copy
{ "status": 200, "content": true | false, //true: successfully uploaded and false: upload failure "message": "OK" }

Mutlipart Upload

When the Object that you need to upload is too large to upload, you can perform a multipart operation. The multipart operation will split the object into multiple parts and perform a quicker upload. In this SDK section, we are going to go over all the SDK methods that are available to perform multipart upload of objects in Stratus.

Create Multipart Instance

To perform multipart operations, you need to get a multipart object instance. We will refer to this component instance in various code snippets where we work with multipart operations being performed on objects stored in a bucket in Stratus. The Bucket reference used in the below code snippet is the component instance.

    
copy
const multipart = bucket.getMultipartInstance("key");

Initiate Multipart Upload

Initiate Multipart Upload Without Options

Using the following SDK method, Stratus will return an uploadId. This ID will allow us to upload multiple pats of the object.

    
copy
// initiate upload const initiateUpload = await multipart.initiateUpload();

Initiate Multipart Upload With Options

Using the following SDK method, Stratus will return an uploadId. This ID will allow us to upload multiple pats of the object. Additionally, using this SDK method you can implement the options parameter to provide type instructions.

Parameters Used

Parameter Name Data Type Definition
type String
  • This parameter is a key in the options JSON Object parameter.
  • This paramater can be used to overwrite the content-type of the object.
  • If you do not pass this parameter, then by default the value of type will be application/octet-stream
    
copy
// initiate upload with options const options = { type: "application/json" } const initiateUpload = await multipart.initiateUpload(options);

Example Response

    
copy
{ "status": 200, "content": { "bucket": "llm-development", "key": "a/cv", "upload_id": "01hyj639a9zfbg8j7q86nsrj6r" }, "message": "OK" }

Upload a Part of the Object

In the following SDK method, we are going to perform uploads of the individual parts of the object. Each part will have a distinct part ranging anywhere between 1 and 1000. While this represents the ordering of the parts, these parts will not necessarily be uploaded in sequence. These parts will be combined in sequence once the upload of all the parts of the objects is complete.

Parameters Used

Parameter Name Data Type Definition
file File The object that needs to be uploaded.
part Number Will contain the ordering of the parts that are being uploaded.
    
copy
const partNumber = 1; const file = document.getElementById("uploadedFiles").files[0] const uploadPart = await multipart.uploadPart(file, partNumber) const uploadPartStart = uploadPart.start(); // to start the request const uploadPartAbort = uploadPart.abort(); // to abort the request

Example Response

    
copy
{ "status": 200, "content": true | false, //true: successfully uploaded and false: upload failure "message": "OK" }

Complete Multipart Upload

The following method allows us to terminate the multipart process once all the parts have been successfully uploaded.

    
copy
const completeUpload = await multipart.completeUpload()

Parameters Used

Parameter Name Data Type Definition
options JSON Object meta: This is an optional JSON Object parameter. It is used to add the meta details of an object that is being uploaded to a bucket. Default value is an empty JSON object

Example Response

    
copy
{ "status": 200, "content": true | false, //true: successfully uploaded and false: upload failure "message": "OK" }

Get Upload Summary

The following SDK method can be used to obtain an operational summary of all the uploaded parts. To view the summary, we will use the getUploadSummary() method.

    
copy
const getUploadSummary = await multipart.getUploadSummary();

Example Response

    
copy
{ "bucket": "zcstratus12345-development", "key": "sasm.txt", "upload_id": "01hyfyeazrrstmt7k5fa7ej726", "status": "PENDING", "parts": [ { "part_number": 1, "size": 0, "uploaded_at": 1716374678999 }, { "part_number": 2, "size": 2797094, "uploaded_at": 1716374678576 }, { "part_number": 4, "size": 0, "uploaded_at": 1716374679136 } ] }

Upload an Object Wrapping all the Multipart Functionality

The following SDK method acts as a wrapper, where the entire multipart upload operation is carried out without employing multiple steps. Using this method, the object is split into multiple parts, uploaded to the bucket in multiple parts, and then combined once all the parts are uploaded.

However, the following method is only recommended to be used in the following conditions:

  • The max_part_size of the object can be the entire file size. However, to ensure a quicker upload, we urge you to keep the max_part_size 100MB or less.
  • The min_part_size of the object should be 5MB or more.
  • The entire object’s size should be 10GB or less.
Note: For object's that are larger than 10GB, we would recommend that you use the individual SDK methods to carry out the multipart upload operation successfully.

Parameters Used

Parameter Name Data Type Definition
file File The object that needs to be uploaded.
partSize Number Will contain the size of each part of the object that is being uploaded.
options JSON Object type: This parameter is a key in this JSON object.
  • It is a String parameter.
  • This paramater can be used to overwrite the content-type of the object.
  • If you do not pass this parameter, then the type of the file will be taken by default. If the file itself does not have a type, then by default the value of type will be application/octet-stream
  • meta: This is an optional JSON Object parameter. It is used to add the meta details of an object that is being uploaded to a bucket. Default value is an empty JSON object

Upload an Object Wrapping all the Multipart Functionality Without Options

    
copy
// upload object const partSize = 10; // in MB const file = document.getElementById("uploadedFiles").files[0] const uploadObject = await multipart.uploadObject(file, partSize);

Upload an Object Wrapping all the Multipart Functionality With Options

    
copy
// upload object with options const partSize = 10; // in MB const file = document.getElementById("uploadedFiles").files[0] const options = { type: "application/json" // content type of the object to overwrite } const uploadObject = await multipart.uploadObject(file, partSize, options);

Example Response

    
copy
{ "status": 200, "content": true | false, //true: successfully uploaded and false: upload failure "message": "OK" }

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