Upload Object
The SDK methods listed in this section will allow you to upload objects to the bucket in various manners. You can upload objects as a string or as a stream. The bucket reference used in the following 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.
Upload Object as a Stream
Using the putObject() SDK method in the following manner, you can upload objects to a bucket as a stream. Store the stream in a variable and then pass that variable in the upload method; putObject()
// create a read stream for upload the object
const file = fs.createReadStream("file_path");
// call the upload method
await bucket.putObject("sam/out/sample.txt", file);
Upload Object as a String
Using the putObject() SDK method in the following manner, you can upload the object as a string.
You will pass the object name, and the data to be stored in the object in string format to the upload method; putObject()
// Upload object as a string
await bucket.putObject("sam/out/sample.txt", "Content of the file");
Upload Object with Options
Using the putObject() SDK method in the following manner, you can use the following options while you upload an object.
- overwrite: This is an option you can use if Versioning for your bucket is not enabled for your bucket. Without versioning, you need to use this option if you wish to overwrite a resource. The default value is ‘false’.
- ttl: This is an option you can use to set Time-to-Live (TTL) in seconds for an object. Value should be greater than or equal to 60 seconds.
- metaData: This is an option you can use to upload meta details of the object that is being uploaded.
- contentType: This is an option you can provide, if you need to set the MIME type of the object.
const options = {
'overwrite': true, //This will overwrite your existing object
'ttl': '300', //time to live in seconds
'metaData': {
'author': 'John'
}
};
const file = fs.createReadStream("filePath");
await bucket.putObject("sam/out/sample.txt", file, options);
Upload Object With Extract Option
When you upload a zipped object using the putObject() SDK method in the following manner, the objects present in the zip will be extracted and uploaded.
const options = {
'ttl': '300', //time to live in seconds
'metaData': {
'author': 'John'
},
// Extract the contents of the given ZIP file and upload each file as a separate object to the bucket
'extractUpload': true
};
const file = fs.createReadStream("filePath");
await bucket.putObject("sam/out/sample.zip", file, options);
Upload Object Using Multipart Utility
In this section we are going to go over the SDK methods that will allow you to successfully upload a large object to a bucket in Stratus.
The multipart upload utility will upload a large file to the bucket in multiple HTTPS requests. All of these requests will be combined into a single object once all the individual parts have been uploaded.
Initiate Upload
To perform multipart operations, you need to get a multipart object instance. You will refer to this component instance in various code snippets where you work with multipart operations being performed on objects stored in a bucket in Stratus.
Parameters Used
| Parameter Name | Data Type | Definition |
|---|---|---|
| bucket | SDK Instance | The bucket reference used in the following code snippet is the component instance. |
const initRes = await bucket.initiateMultipartUpload("sam/out/sample.txt");
console.log(initRes);
Example of Expected Response
{
"bucket": "zcstratus123-development",
"key": "sam/out/sample.txt",
"upload_id": "01j7xbm4vm5750zbedxqgc4q6m",
"status": "PENDING"
}
Upload Parts of the Object
The following code snippet illustrates the manner in which you can perform uploads of the individual parts of the object.
Each part will have a distinct partNumber 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.
const partNumber = 1;
const file = fs.createReadStream("filePath");
await bucket.uploadPart("sam/out/sample.txt", "uploadId", file, partNumber);
Get Multipart Upload Summary
The following example code snippet demonstrates the manner in which you can use the getMultipartUploadSummary() SDK method to obtain an operational summary of all the uploaded parts.
const uploadSummaryRes = await bucket.getMultipartUploadSummary("sam/out/sample.txt", "upload_id");
console.log(uploadSummaryRes);
Example of Expectedd Response
{
"bucket": "zcstratus12345-development",
"key": "sam/out/sample.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
}
]
}
Complete Multipart Upload of the Object
The following example code snippet demonstrates the manner in which you can terminate the multipart process once all the parts have been successfully uploaded.
To complete the process, you will need to pass the uploadId to the completeMultipartUpload() method.
Example Code Snippet Implementing Multipart Upload
const fs = require('fs');
module.exports = async (req, res) => {
url = req.url;
switch (url) {
case '/':
const auth = new ZCAuth();
const authInit = await auth.init(req);
const stratus = new Stratus();
/** create a bucket instance */
const bucket = stratus.bucket("bucket_name");
/** multipart upload */
const key = 'sample.mp4';
// initiate multipart upload
const initRes = await bucket.initiateMultipartUpload(key);
// get upload Id from initiate upload response.
const uploadId = initRes['upload_id'];
const filePath = '/Users/Aliza//sam.mp4';
const partSize = 50 * 1024 * 1024; // in Mb
const fileStream = fs.createReadStream(
filePath,
{ highWaterMark: partSize }
);
let partNumber = 1;
const uploadPromises = [];
fileStream.on('data', async (partData) => {
// Push each part upload to the promises array for parallel upload
const partUploadPromise = bucket.uploadPart(
key,
uploadId,
partData,
partNumber
);
uploadPromises.push(partUploadPromise);
console.log('Part Number: ', partNumber);
partNumber++;
});
// Wait for all parts to be uploaded in parallel
fileStream.on('end', async () => {
await Promise.all(uploadPromises);
// Complete the multipart upload
await bucket.completeMultipartUpload(key, uploadId);
console.log('Successfully Uploaded');
});
res.end();
break;
default:
res.writeHead(404);
res.write('You might find the page you are looking for at "/" path');
break;
}
}
Upload an Object Using the Transfer Manager Utility
Create Transfer Manager Instance
const transferManager = new TransferManager(bucket); // create transfer manager instance
Multipart Upload
Create Multipart Upload Instance
The following code snippet will create a multipart instance to initiate multipart upload.
const multipart = await transferManager.createMultipartInstance("sam/out/sample.txt"); // create multipart instance
If you are required to create an instance for an already initialized multipart upload operation, then copy and use the code snippet given below.
const multipart = await transferManager.createMultipartInstance("sam/out/sample.txt", "uploadId");
Upload Parts of the Object
In the following example code snippet, you need to initialize a multipart instance, as defined in the Create Multipart Upload Instance section.
With this instance, you can use the uploadPart() SDK method to upload parts of the object.
await multipart.uploadPart(fs.createReadStream("filePath"), partNumber);
Upload Summary
The following code snippet demonstrates the use of the getUploadSummary() SDK method to get a summary of the upload process.
const summaryRes = await multipart.getUploadSummary();
console.log(summaryRes);
Complete Upload
The following code snippet demonstrates the use of the completeUpload() SDK method to complete the upload process.
await multipart.completeUpload();
Upload Object Using Wrapper
The following code snippet demonstrates the use of the putObjectAsParts() 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.
const file = fs.createReadStream("filePath");
const partSize = 50 // in MB
const objectPartUploadRes = await transferManager.putObjectAsParts("sam/out/sample.txt",file, partSize);
console.log(objectPartUploadRes);
Generate Presigned URL to Upload an Object
Presigned URLs are secure URLs that authenticated users can share with their non-authenticated users. This URL will provide non-authenticated users with temporary authorization to access objects.
The bucket reference used in the following code snippet is the component instance.
Parameters Used
| Parameter Name | Data Type | Definition |
|---|---|---|
| key | String | A mandatory parameter. Will hold the complete name of the object along with its path. |
| urlAction | Request Method | A mandatory parameter. This is the parameter that will allow you to generate a presigned URL for an upload (PUT) action.
|
| expiry | String | This is an optional parameter. The URL validity time in seconds.
|
| activeFrom | String | This is an optional parameter. This parameter will contain the time after which the URL is valid.
|
const signedURLRes = await bucket.generatePreSignedUrl("sam/out/sample.txt", 'PUT', {
'expiryIn': 100, // expiry time in seconds
'activeFrom':'12334454327', // activate the url in the given date
});
console.log(signedURLRes);
Example mof Expected Response
{
signature: "https://sadi-development.zohostratus.com/_signed/text.txt?organizationId=96862383&stsCredential=96858154-96862383&stsDate=1747896279887&stsExpiresAfter=300&stsSignedHeaders=host&stsSignature=3YBUX1HFSxNQzQJjFrln82AyJsEEuC5T9dsZwWxGyEE"
}
Example Code Snippet: Upload with Presigned URL
const axios = require('axios');
const fs = require('fs');
// Replace this with the actual pre-signed URL generated for your upload.
const url = ‘https: //sadi-development.zohostratus.com/_signed/text.txt?organizationId=96862383&stsCredential=96858154-96862383&stsDate=1747911331272&stsExpiresAfter=300&stsSignedHeaders=host&stsSignature=K9vuqC7JaATLeM3TX4xXWx0OHcSflbYQ2jCrbKSAAIE';
// Replace ‘file_path’ with your actual file path
const data = fs.createReadStream(’/Users/amelia - 426 / Documents / JavaScript - SDK / Stratus / sam.py’);
// Optional headers; content type may vary depending on the file type
const headers = {
// ‘Content-Type’: ‘application/json’, // adjust if uploading non-JSON files (e.g., ’text/plain’ or ‘application/octet-stream’)
// ‘overwrite’: ’true’, // optional header
};
(async () => {
try {
const response = await axios.put(url, data, {
headers
});
if (response.status === 200) {
console.log('Object uploaded successfully');
} else {
console.log('⚠️ Error uploading object:', response.data);
}
} catch (error) {
console.error('Upload failed:', error.response?.data || error.message);
}
})();
Last Updated 2026-07-02 14:51:41 +0530 IST
Yes
No
Send your feedback to us