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

@akronbook/cloud-storage

v0.0.28

Published

Handle different types of cloud storage (e.g. Azure, S3, etc.) using a consistent API

Downloads

72

Readme

What problem is cloud-storage aims to solve?

You are building a browser-based or NodeJS application. You need to store some data in the cloud storage. But there are many challenges a developer will soon face when trying to write the code:

  • Different cloud storage has different APIs. For example, Azure uses SAS tokens for accessing the Azure Storage. Amazon uses AWS SDK to generate pre-signed URLs for acessing S3 storage. Aliyun uses its own "Object Storage Service" that are subtly different from AWS. As a developer, how to support different storage APIs and to avoid deep learning curve on each different platform?
  • Even on the same cloud storage platform (e.g. AWS), there are potentially multiple ways of accessing the cloud storage. For example, AWS offers the ability to connect API Gateway to an AWS S3 bucket (https://www.youtube.com/watch?v=7T5VbMEJStQ&t=57s), thus allowing developers to upload files to AWS S3 bucket via simple REST APIs. But there is a caveat: the maximum payload size is 10M, thus the solution is not feasible for managing common video files, or large files in general.

In short, it is not trivial to write storage-related code that is simple, secure and scalable.

cloud-storage library to the rescue

This is a javascript library that helps you to simply the development of cloud storage. It aims to support all common cloud storage APIs. Currently, it supports:

  • AWS S3
  • WO Cloud

The library chooses to use pre-signed URLs (vs. REST APIs) for reading and writing files. The thought is to avoid payload size limit due to REST API restrictions on most cloud storage platforms.

How to use it?

  • Install the SDK

    • npm install @akronbook/cloud-storage --save
    • npm install rxjs --save-dev
  • Make sure that globals are properly defined. For example, cloud-storage assumes that AWS global is defined by the caller, thus if you are going to make use cloud-storage in a Node.JS project, make sure to set up the AWS global object like this:

import AWS from 'aws-sdk';
(globalThis as any).AWS = AWS;
  • Write your code to upload files
import {StorageManager} from "@akronbook/cloud-storage";
import { Subject } from 'rxjs'; 

const storageCredential: StorageCredential = {
    "storageType": "aws",
    "apiBase": "",
    "folder": "YOUR_FOLDER_IN_THE_BUCKET",
    "credentials": {
        "AccessKeyId": "YOUR_AWS_ACCESS_KEY",
        "SecretAccessKey": "YOUR_AWS_SECRET",
        "SessionToken": "YOUR_SESSION_TOKEN",
        "Expiration": "2023-02-15T06:15:59.000Z",
        "RegionalId": "YOUR_REGION_ID",
        "Bucket": "YOUR_BUCKET_NAME"
    }
};

const storage = StorageManager.CreateStorage('aws');
const subject = new Subject<number>();
subject.subscribe({
    next: (v) => console.log(`bytes uploaded=${v}`),
});
await storage.uploadFile(storageCredential, byteArray, 'myfile.txt', subject);
  • Write your code to download files
const fileUrl = storage.getFileUrl(storageCredential, 'myfile.txt');
// Now you can use the fileUrl to download the file

Notes

Currently, the supported storageTypes are:

  • aws
  • wo

The token format

Future development

We will add supports to some other storage types:

  • azure
  • oss (i.e. aliyun cloud storage)

We will also add supports to:

  • delete files
  • check whether a file exists or not