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

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(fileBuffer, {
  key: "path/to/file.jpg", // required - path/name in bucket
  bucketName: "bucket-name", // optional if default bucket set
  visibility: "private", // optional, defaults to 'private'
  region: "us-east-1", // optional, overrides default region
  contentType: "image/jpeg", // optional, specify mime type
});

Delete a File

await storage.files.delete(
  "bucket-name", // optional if default bucket set
  "path/to/file.jpg" // file key in bucket
);

Get a Signed URL for Download

const url = await storage.files.getSignedUrl(
  "bucket-name", // optional if default bucket set
  "path/to/file.jpg", // file key in bucket
  {
    type: "download",
    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(
  "bucket-name",
  "path/to/file.jpg",
  {
    type: "operation-type", // required
    // ... other parameters depending on operation
  }
);

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

Multipart Upload

// 1. Start the multipart upload
const upload = await storage.files.startMultipartUpload(
  "bucket-name",
  "large-file.zip",
  {
    totalParts: 3, // required
    mimeType: "application/zip", // required
    visibility: "public", // optional
  }
);

// 2. Upload individual parts
for (let partNumber = 1; partNumber <= 3; partNumber++) {
  const partResult = await storage.files.uploadPart(
    upload.uploadId,
    partNumber,
    filePartBuffer,
    {
      key: "large-file.zip", // required
      bucketName: "bucket-name", // optional if default bucket set
      totalParts: 3, // required
    }
  );
  parts.push(partResult);
}

// 3. Complete the multipart upload
await storage.files.completeMultipartUpload(upload.uploadId, parts, {
  key: "large-file.zip", // required
  bucketName: "bucket-name", // optional if default bucket set
});

If you need to cancel the upload:

await storage.files.cancelMultipartUpload(uploadId, {
  bucketName: "bucket-name",
  key: "file-key",
});

Bucket Operations

List Bucket Contents

const contents = await storage.bucket.listContents(
  "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("bucket-name", "./file.jpg");
} catch (error) {
  console.error("Upload failed:", error);
}