@akmyradov/cloudstorage

0.0.3 • Public • Published

Cloud Storage Client for NodeJS

Supported Services:
Google Cloud Storage
Amazon S3 Storage
***More to come...

Features

  • Uploading File
  • Deleting File
  • Retrieving File
  • Retrieve as JSON
  • Check if File exists
  • Check if File is missing
  • Retrieve Public URL
  • Download File from Cloud

Installation

Run: npm install @akmyradov/cloudstorage multer

Example for Google Cloud:

import { Storage, GoogleCloudStorage} from '@akmyradov/cloudstorage';

let storage = new Storage(new GoogleProvider(
    'project-id',
    'bucket-name',
    'path/to/service-account.json',
    'destination-folder-path'
));

Example for Amazon S3 Storage:

import { Storage, AmazonS3Storage} from '@akmyradov/cloudstorage';

const storage = new Storage(new AmazonS3Storage(
    'region-name',
    'bucket-name',
    'access-key',
    'access-secret-key',
    'destination-folder-path'
));

To upload a file (You have to pass 'req' from express):

storage.put('save-file-name', req.file).then(file => {
    console.log(file.publicUrl());
};

Delete file:

storage.delete('file-name').then(response => {
    console.log('deleted');
}).catch(error => {
    console.log(error)
});

Read File Contents:

storage.get('file.txt').then(contents => {
    console.log(contents);
}).catch(error => {
    console.log(error);
});

Retrieve File Contents as JSON:

storage.json('file.json').then(data => {
    console.log(data);
}).catch(error => {
    console.log(error);
});

Check if File exists:

storage.exists('file-name').then(response => {
    console.log(response);
})

Check if File is missing:

storage.missing('file-name').then(response => {
    console.log(response);
})

Retrieve File URL:

storage.url('file-name').then(url => {
    console.log(url);
}).catch(error => {
    console.log(error);
})

Download File:

storage.download('file-name').then(file => {
   file.pipe(res.attachment('file-name'));
}).catch(error => {
    console.log(error);
});

Contact

Reach out at azat@akmyradov.me

Package Sidebar

Install

npm i @akmyradov/cloudstorage

Weekly Downloads

2

Version

0.0.3

License

ISC

Unpacked Size

12 kB

Total Files

6

Last publish

Collaborators

  • azatakmyradov