@pandodev/bucket-sdk
v1.0.1
Published
Internal Pando SDK with Digital Ocean Buckets functionality
Readme
Installation
npm install @pandodev/bucket-sdk
Configuration
Create a .env file in your project and set the following variables:
DO_SPACES_ENDPOINT="your-region.digitaloceanspaces.com"
DO_SPACES_REGION="your-region"
DO_SPACES_BUCKET="project-name"
DO_SPACES_ROOT_FOLDER="env-name"
DO_SPACES_KEY="your-do-key"
DO_SPACES_SECRET="your-do-secret"Usage
Import and Initialize the SDK
import { BucketService } from '@pandodev/bucket-sdk';
const bucketService = new BucketService();Alternatively, you can pass configuration directly:
const bucketService = new BucketService({ key: 'your-do-key', secret: 'your-do-secret', endpoint: 'your-region.digitaloceanspaces.com', region: 'your-region' });
Uploading a File
/**
* @param file - The file buffer array to be upoloaded.
* @param type - Enum type of the file type (will be saved in the corresponding folder).
* @param subfolder - Specify a folder withing the containing file type folder (optional).
* @returns url and fileName
*/
await bucketService.uploadFile(fileObj, FileType.Video, 'user-id');Deleting a File
/**
* @param url - The URL of the file to be deleted.
* @returns true if sucessfull
*/
await bucketService.deleteFile('https://distinction.sfo3.cdn.digitaloceanspaces.com/filename');Deleting multiple Files
/**
* @param urls - The URL array of the files to be deleted.
* @returns count of deleted files
*/
await bucketService.deleteFiles(['https://distinction.sfo3.cdn.digitaloceanspaces.com/filename1', 'https://distinction.sfo3.cdn.digitaloceanspaces.com/filename2']);