Skip to content

A library for providing a global interface for interacting with different cloud storage providers.

Notifications You must be signed in to change notification settings

Frame-One-Software/frame-one-bucket-adapter

Repository files navigation

Frame One Table Logo NPM NPM GITHUB

Installation

npm

npm install frame-one-bucket-adapter

yarn

yarn add frame-one-bucket-adapter

Usage

S3

import S3 from "aws-sdk/clients/s3";
import {S3BucketAdapter} from "frame-one-bucket-adapter";

const s3 = new S3({
    accessKeyId: '/* access key here */', // For example, 'AKIXXXXXXXXXXXGKUY'.
    secretAccessKey: '/* secret key here */', // For example, 'm+XXXXXXXXXXXXXXXXXXXXXXDDIajovY+R0AGR'.
    region: '/* region here */' // For example, 'us-east-1'.
});

const bucket = new S3BucketAdapter({bucketName: '/* bucket name here */', s3});

const fileName = "test-image"

// upload file
await bucket.upload("/* file path or Buffer */", {fileName, contentType: "image/png"});

// check the file exists on the bucket
const exists = await bucket.exists(fileName);
if (!exists) {
    throw new Error("Could not find file.");
}

// create a read stream
const readStream = await bucket.createReadStream(fileName);

Google Storage

import {Bucket, Storage} from "@google-cloud/storage";
import {GoogleStorageBucketAdapter} from "frame-one-bucket-adapter";

const storage = new Storage({
    projectId: '/* project id here */',
    credentials: {
        client_email: '/* client email here */',
        private_key: '/* private key here */',
    }
});

const bucket = new GoogleStorageBucketAdapter({bucketName: '/* bucket name here */', storage});

const fileName = "test-image"

// upload file
await bucket.upload("/* file path or Buffer */", {fileName, contentType: "image/png", gzip: true});

// check the file exists on the bucket
const exists = await bucket.exists(fileName);
if (!exists) {
    throw new Error("Could not find file.");
}

// create a read stream
const readStream = await bucket.createReadStream(fileName, {validation: true});