If you want sdk support for languages that is not supported yet, please
contact us so we can add it. you can also integrate
the api directly in your own applications.
Installation
npm install @apexxcloud/sdk-node
Initialization
const ApexxCloud = require("@apexxcloud/sdk-node");
const storage = new ApexxCloud({
accessKey: process.env.APEXXCLOUD_ACCESS_KEY,
secretKey: process.env.APEXXCLOUD_SECRET_KEY,
region: "bucket-region",
bucket: "bucket-name",
});
File Operations
Upload a File
// Simple upload
const result = await storage.files.upload("path/to/file.jpg", fileBuffer, {
bucketName: "bucket-name", // optional if default bucket set
visibility: "private", // optional, defaults to 'private'
contentType: "image/jpeg", // optional, specify mime type
});
Delete a File
await storage.files.delete("path/to/file.jpg", {
bucketName: "bucket-name", // optional if default bucket set
});
Get a Signed URL for Download
const url = await storage.files.getSignedUrl("download", {
bucketName: "bucket-name", // optional if default bucket set
key: "path/to/file.jpg",
expiresIn: 3600, // optional, defaults to 1 hour (in seconds)
});
Generate Pre-Signed URLs for Operations
// All operations use storage.files.getSignedUrl instead of storage.getSignedUrl
const signedUrl = await storage.files.getSignedUrl("upload", {
bucketName: "bucket-name", // optional if default bucket set
key: "path/to/file.jpg",
expiresIn: 3600, // optional, defaults to 1 hour (in seconds)
});
Available operation types:
upload
: Create new file
delete
: Delete existing file
download
: Download file
start-multipart
: Initialize multipart upload
uploadpart
: Upload individual part
completemultipart
: Complete multipart upload
cancelmultipart
: Cancel multipart upload
Purge a File Cache
const result = await storage.files.purge("path/to/file.jpg", {
bucketName: "bucket-name", // optional if default bucket set
});
This will purge cdn cache for the original file and all the transformations of the file
Multipart Upload
// 1. Start the multipart upload
const upload = await storage.files.startMultipartUpload("large-file.zip", {
bucketName: "bucket-name", // optional if default bucket set
totalParts: 3, // required
mimeType: "application/zip", // optional
visibility: "public", // optional
});
// 2. Upload individual parts
const parts = [];
for (let partNumber = 1; partNumber <= 3; partNumber++) {
const partResult = await storage.files.uploadPart(
"large-file.zip",
filePartBuffer,
{
bucketName: "bucket-name", // optional if default bucket set
uploadId: upload.uploadId,
partNumber: partNumber,
totalParts: 3,
}
);
parts.push(partResult);
}
// 3. Complete the multipart upload
await storage.files.completeMultipartUpload("large-file.zip", parts, {
bucketName: "bucket-name", // optional if default bucket set
uploadId: upload.uploadId,
});
If you need to cancel the upload:
await storage.files.cancelMultipartUpload("file-key", {
bucketName: "bucket-name", // optional if default bucket set
});
Bucket Operations
List Bucket Contents
const contents = await storage.bucket.listContents({
bucketName: "bucket-name", // optional if default bucket set
prefix: "folder/", // optional, filter by prefix
page: 1, // optional, defaults to 1
limit: 20, // optional, defaults to 20
});
Error Handling
The SDK uses a consistent error handling pattern:
try {
await storage.files.upload("./file.jpg", fileBuffer, {
bucketName: "bucket-name", // optional if default bucket set
});
} catch (error) {
console.error("Upload failed:", error);
}