ObjectManager

Interacts with an S3 client to perform various operations on objects in a bucket.

Constructor

new ObjectManager(clientKey, clientSecret, options)

Creates a new instance of the constructor.

Parameters:
NameTypeDescription
clientKeystring

The access key ID for authentication.

clientSecretstring

The secret access key for authentication.

optionsobjectManagerOptions

Optional settings for the constructor.

Tutorials
Example
import { ObjectManager } from "@filebase/sdk";
const objectManager = new ObjectManager("KEY_FROM_DASHBOARD", "SECRET_FROM_DASHBOARD", {
  bucket: "my-default-bucket",
  maxConcurrentUploads: 4,
  gateway: {
    endpoint: "https://my-default-gateway.mydomain.com
    token: SUPER_SECRET_GATEWAY_TOKEN
  }
});

Methods

(async) upload(key, source, metadataopt, optionsopt) → {Promise.<objectHeadResult>}

Uploads a file or a CAR file to the specified bucket.

If the source parameter is an array of objects, it will pack multiple files into a CAR file for upload. The method returns a Promise that resolves to an object containing the CID (Content Identifier) of the uploaded file and an optional entries object when uploading a CAR file.

Parameters:
NameTypeAttributesDescription
keystring

The key or path of the file in the bucket.

sourceBuffer | ReadableStream | Array.<Object>

The content of the object to be uploaded. If an array of files is provided, each file should have a 'path' property specifying the path of the file and a 'content' property specifying the content of the file. The SDK will then construct a CAR file locally and use that as the content of the object to be uploaded.

metadataObject<optional>

Optional metadata for pin object

optionsobjectOptions<optional>

The options for uploading the object.

Returns:
Type: 
Promise.<objectHeadResult>
Example
// Upload Object
await objectManager.upload("my-object", Buffer.from("Hello World!"));
// Upload Object with Metadata
await objectManager.upload("my-custom-object", Buffer.from("Hello Big World!"), {
  "application": "my-filebase-app"
});
// Upload Directory
await objectManager.upload("my-first-directory", [
 {
  path: "/testObjects/1.txt",  // Virtual Path to store contents at within IPFS Folder/Directory
  content: Buffer.from("upload test object", "utf-8"),
 },
 {
  path: "/testObjects/deep/1.txt",
  content: Buffer.from("upload deep test object", "utf-8"),
 },
 {
  path: "/topLevel.txt",
  content: Buffer.from("upload top level test object", "utf-8"),
 },
]);

(async) get(key, optionsopt) → {Promise.<(objectHeadResult|false)>}

Gets an objects info and metadata using the S3 API.

Parameters:
NameTypeAttributesDescription
keystring

The key of the object to be inspected.

optionsobjectOptions<optional>

The options for inspecting the object.

Returns:
Type: 
Promise.<(objectHeadResult|false)>

(async) download(key, optionsopt) → {Promise.<Object>}

Downloads an object from the specified bucket using the provided key.

Parameters:
NameTypeAttributesDescription
keystring

The key of the object to be downloaded.

optionsobjectOptions<optional>

The options for downloading the object.

Returns:
  • A promise that resolves with the contents of the downloaded object as a Stream.
Type: 
Promise.<Object>
Example
// Download object with name of `download-object-example`
await objectManager.download(`download-object-example`);

(async) list(options) → {Promise.<listObjectsResult>}

Retrieves a list of objects from a specified bucket.

Retrieves a list of objects from a specified bucket.

Parameters:
NameTypeDescription
optionslistObjectOptions

The options for listing objects.

Returns:
  • A promise that resolves to an array of objects.
Type: 
Promise.<listObjectsResult>
Example
// List objects in bucket with a limit of 1000
await objectManager.list({
  MaxKeys: 1000
});

(async) delete(key, optionsopt) → {Promise.<Boolean>}

Deletes an object from the specified bucket using the provided key.

Parameters:
NameTypeAttributesDescription
keystring

The key of the object to be deleted.

optionsobjectOptions<optional>

The options for deleting the file.

Returns:
  • A Promise that resolves with the result of the delete operation.
Type: 
Promise.<Boolean>
Example
// Delete object with name of `delete-object-example`
await objectManager.delete(`delete-object-example`);

(async) copy(sourceKey, destinationBucket, optionsopt) → {Promise.<Boolean>}

Copy the object from sourceKey in the sourceBucket to destinationKey in the destinationBucket.

If the destinationKey is not provided, the object will be copied with the same key as the sourceKey.

Parameters:
NameTypeAttributesDescription
sourceKeystring

The key of the object to be copied from the sourceBucket.

destinationBucketstring

The bucket where the object will be copied to.

optionscopyObjectOptions<optional>

Additional options for the copy operation.

Returns:
  • A Promise that resolves with the result of the copy operation.
Type: 
Promise.<Boolean>
Example
// Copy object `copy-object-test` from `copy-object-test-pass-src` to `copy-object-test-pass-dest`
// TIP: Set bucket on constructor, it will be used as the default source for copying objects.
await objectManager.copy(`copy-object-test`, `copy-object-dest`, {
  sourceBucket: `copy-object-src`
});