Constructor
new ObjectManager(clientKey, clientSecret, options)
Creates a new instance of the constructor.
Name | Type | Description |
---|---|---|
clientKey | string | The access key ID for authentication. |
clientSecret | string | The secret access key for authentication. |
options | objectManagerOptions | Optional settings for the constructor. |
- Source
- Tutorials
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.
Name | Type | Attributes | Description |
---|---|---|---|
key | string | The key or path of the file in the bucket. | |
source | Buffer | | 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. | |
metadata | Object | <optional> | Optional metadata for pin object |
options | objectOptions | <optional> | The options for uploading the object. |
- Source
- Type:
- Promise.<objectHeadResult>
// 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.
Name | Type | Attributes | Description |
---|---|---|---|
key | string | The key of the object to be inspected. | |
options | objectOptions | <optional> | The options for inspecting the object. |
- Source
- Type:
- Promise.<(objectHeadResult|false)>
(async) download(key, optionsopt) → {Promise.<Object>}
Downloads an object from the specified bucket using the provided key.
Name | Type | Attributes | Description |
---|---|---|---|
key | string | The key of the object to be downloaded. | |
options | objectOptions | <optional> | The options for downloading the object. |
- Source
- A promise that resolves with the contents of the downloaded object as a Stream.
- Type:
- Promise.<Object>
// 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.
Name | Type | Description |
---|---|---|
options | listObjectOptions | The options for listing objects. |
- Source
- A promise that resolves to an array of objects.
- Type:
- Promise.<listObjectsResult>
// 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.
Name | Type | Attributes | Description |
---|---|---|---|
key | string | The key of the object to be deleted. | |
options | objectOptions | <optional> | The options for deleting the file. |
- Source
- A Promise that resolves with the result of the delete operation.
- Type:
- Promise.<Boolean>
// 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.
Name | Type | Attributes | Description |
---|---|---|---|
sourceKey | string | The key of the object to be copied from the sourceBucket. | |
destinationBucket | string | The bucket where the object will be copied to. | |
options | copyObjectOptions | <optional> | Additional options for the copy operation. |
- Source
- A Promise that resolves with the result of the copy operation.
- Type:
- Promise.<Boolean>
// 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`
});