npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elevate-cloud-storage

v2.6.4

Published

This is npm package which exports the functions to upload file in GCP, AWS S3 and AZURE

Downloads

422

Readme

elevate-Cloud-Storage

This package exports the methods to upload file in GCP, AWS S3, OCI and AZURE

PreRequisite

You must have all type of required credentials of AWS/GCP/AZURE/OCI cloud storage while calling upload methods

Installation

npm i elevate-cloud-storage

Usage Google Cloud Storage

To upload file

const { GcpFileHelper } = require('elevate-cloud-storage');
const path = require('path');

// assuming logo.png is present in your root directory
const filePath = path.join(__dirname, 'logo.png'); // Stored file path - pass absolute path.

const destFileName = 'logo.png'; // fileName to be saved in google cloud
const bucketName = '<bucket-name>'; // google cloud storage bucket in which file gets saved
const gcpProjectId = '<gcp-project-id>'; // google cloud storage project id - Get from gcp console

// assuming gcp.json is present in your root directory
// google cloud storage json configuration file - pass absolute path
// download file from manage storage api key section in gcp console
const gcpJsonFilePath = path.join(__dirname, 'gcp.json');

GcpFileHelper.uploadFile({filePath, destFileName, bucketName, gcpProjectId, gcpJsonFilePath}).then(response => {
    console.log(response);
}).catch(err => {
    console.log(error);
});

To generate signed url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - location from bucket - example - users/abc.png
    bucketName: '<Bucket-Name>', // google cloud storage bucket in which action is peformed over file
    actionType: 'write', // signed url usage type - example ('read' | 'write' | 'delete' | 'resumable')
    expiry: Date.now() + 1000 * 60 * 30, // signed url expiration time - In ms from current time - type number | string | Date
    gcpProjectId: '<Gcp-Project-Id>', // google cloud storage project id
    gcpJsonFilePath: '<Gcp-Json-File-Path>', // google cloud storage json configuration file absolute path for connectivity
    contentType: 'multipart/form-data', // content type of file, example multipart/form-data, image/png, csv/text etc
};

GcpFileHelper.getSignedUrl(options).then(response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});

To get downloadable url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - location from bucket - example - users/abc.png
    bucketName: '<Bucket-Name>', // google cloud storage bucket in which action is peformed over file
    gcpProjectId: '<Gcp-Project-Id>', // google cloud storage project id
    gcpJsonFilePath: '<Gcp-Json-File-Path>', // google cloud storage json configuration file absolute path for connectivity
};

GcpFileHelper.getDownloadableUrl(options).then(response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});

Usage Amazon Web Service S3 storage

To upload file

const { AwsFileHelper } = require('elevate-cloud-storage');

// assuming logo.png is present in your root directory
const filePath = path.join(__dirname, 'logo.png'); // Stored file path - pass absolute path.

const destFileName = 'logo.png'; // fileName to be saved in aws s3 bucket
const bucketName = '<bucket-name>'; // aws s3 bucket in which file gets saved
const accessKeyId = '<access-key-id>'; // aws s3 access key id - Get from aws console
const secretAccessKey = '<secret-access-key>' // aws s3 secret access key - Get from aws console

// aws region where bucket will be located for fastest delivery of resources - Get bucket-region from aws s3 console
const bucketRegion = '<bucket-region>'

AwsFileHelper.uploadFile({filePath, destFileName, bucketName, accessKeyId, secretAccessKey, bucketRegion}).then(response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});

To generate signed url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - i.e location from bucket - ex - users/abc.png
    bucketName: '<Bucket-Name>', // aws s3 storage bucket in which action is peformed over file
    actionType: 'putObject', // signed url usage type - example ('putObject' | 'getObject')
    expiry: 30 * 60, // signed url expiration time - In sec - type number
    accessKeyId: '<Access-Key-Id>', // aws s3 access key id
    secretAccessKey: '<Secret-Access-Key>', // aws s3 secret access key
    bucketRegion: '<Bucket-Region>' // aws region where bucket will be located, example - 'ap-south-1'
}

AwsFileHelper.getSignedUrl(options).then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
});

To get downloadable url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - i.e location from bucket - ex - users/abc.png
    bucketName: '<Bucket-Name>', // aws s3 storage bucket in which action is peformed over file
    bucketRegion: '<Bucket-Region>' // aws region where bucket will be located, example - 'ap-south-1'
}

AwsFileHelper.getDownloadableUrl(options).then(response => {
    console.log(response);
}).catch(err => {
    console.log(err);
});

Usage Azure Storage

To upload file

const { AzureFileHelper } = require('elevate-cloud-storage');

// assuming logo.png is present in your root directory
const filePath = path.join(__dirname, 'logo.png'); // Stored file path - pass absolute path.

const destFileName = 'logo.png'; // fileName to be saved in azure container
const containerName = '<container-name>'; // container in which file gets saved
const accountKey = '<account-key>' // account name of azure storage - get from storage console
const accountName = '<account-name>' // account key of azure storage - get from storage console 

AzureFileHelper.uploadFile({filePath, destFileName, containerName, accountName, accountKey}).then(response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});

To generate signed url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - i.e location from container - ex - users/abc.png
    containerName: '<Container-Name>', // container in which file gets saved
    expiry: 30, // signed url expiration time - In minute - type number
    actionType: "w", // signed url usage type - example ('w' | 'r' | 'wr' | 'racwdl') - pair of any alphabets among racwdl
    accountName: '<Account-Name>', // account name of azure storage 
    accountKey: '<Account-Key>', // account key of azure storage 
    contentType: 'multipart/form-data' // content type of file, example multipart/form-data, image/png, csv/text etc
};

AzureFileHelper.getSignedUrl(options).then(response => {
    console.log(response);
}).catch(err => {
    console.log(err);
});

To get downloadable url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - i.e location from container - ex - users/abc.png
    containerName: '<Container-Name>', // container in which file gets saved
    expiry: 30, // signed url expiration time - In minute - type number
    actionType: "rw", // signed url usage type - example ('w' | 'r' | 'wr' | 'racwdl') - pair of any alphabets among racwdl
    accountName: '<Account-Name>', // account name of azure storage 
    accountKey: '<Account-Key>', // account key of azure storage
};

AzureFileHelper.getDownloadableUrl(options).then(response => {
    console.log(response);
}).catch(err => {
    console.log(err);
});

Usage Oracle Cloud Object Storage

To upload file

const { OciFileHelper } = require('elevate-cloud-storage');

// assuming logo.png is present in your root directory
const filePath = path.join(__dirname, 'logo.png'); // Stored file path - pass absolute path.

const destFileName = 'logo.png'; // fileName to be saved in oci bucket
const bucketName = '<bucket-name>'; // oci bucket in which file gets saved
const accessKeyId = '<access-key-id>'; // oci access key id - Get from oci 
const secretAccessKey = '<secret-access-key>' // oci secret access key - Get from awoci
const endpoint = '<endpoint>' // OCI endpoint

// oci region where bucket will be located for fastest delivery of resources - Get bucket-region from oci console
const bucketRegion = '<bucket-region>'

OciFileHelper.uploadFile({filePath, destFileName, bucketName, accessKeyId, secretAccessKey, bucketRegion, endpoint}).then(response => {
    console.log(response);
}).catch(error => {
    console.log(error);
});

To generate signed url

const options = {
    destFilePath: 'users/abc.png', // Stored file path - i.e location from bucket - ex - users/abc.png
    bucketName: '<Bucket-Name>', // oci storage bucket in which action is peformed over file
    actionType: 'putObject', // signed url usage type - example ('putObject' | 'getObject')
    expiry: 30 * 60, // signed url expiration time - In sec - type number
    accessKeyId: '<Access-Key-Id>', // oci access key id
    secretAccessKey: '<Secret-Access-Key>', // oci secret access key
    bucketRegion: '<Bucket-Region>' // oci region where bucket will be located, example - 'ap-hyderabad-1'
     endpoint :  '<endpoint>' // OCI endpoint
}

OciFileHelper.getSignedUrl(options).then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
});

To get downloadable url

const options = {
   destFilePath: 'users/abc.png', // Stored file path - i.e location from bucket - ex - users/abc.png
    bucketName: '<Bucket-Name>', // oci storage bucket in which action is peformed over file
    actionType: 'putObject', // signed url usage type - example ('putObject' | 'getObject')
    expiry: 30 * 60, // signed url expiration time - In sec - type number
    accessKeyId: '<Access-Key-Id>', // oci access key id
    secretAccessKey: '<Secret-Access-Key>', // oci secret access key
    bucketRegion: '<Bucket-Region>' // oci region where bucket will be located, example - 'ap-hyderabad-1'
    endpoint :  '<endpoint>' // OCI endpoint
}

OciFileHelper.getDownloadableUrl(options).then(response => {
    console.log(response);
}).catch(err => {
    console.log(err);
});

Thanks for using this, Looking forward to your contributions 😎 .