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

@mediasuite/cloud-storage

v0.6.1

Published

upload and download files from various providers

Downloads

383

Readme

cloud-storage

Upload and download files from various providers. The goal of this module is provide a simple file upload and download abstraction allowing for the possibility of switching out the provider at any time without breaking existing code.

NPM

Media Suite

Build Status

Installation

npm install @mediasuite/cloud-storage --save

Usage

require module

const storage = require('@mediasuite/cloud-storage')

setup configuration

const config = {
  adapter: {
    provider: 'amazon',
    keyId: '', // access key id
    key: '', // secret key
    region: '', // amazon region
    container: '' // s3 bucket
  }
}

configuration options

pkgcloud providers

Warning: Currently only actively developing for filesystem and AWS, some features may not be supported for pkgcloud providers.

For pkgcloud providers see pgkcloud storage for most options. In addition use key container to specify which cloud container to upload to. (For amazon this is a bucket)

filesystem provider
{
  adapter: {
    provider: 'filesystem',
    path: '' // path on local filesystem
  }
}

upload a file

storage(config).upload('my-file.png', data)
  .then(() => {
    // do something
  })
  .catch(err => {
    // handle any errors
  })

download a file

storage(config).download('my-file.png')
  .then(fileStream => {
    // do something with fileStream
    // eg. in an express route -> fileStream.pipe(res)
  })
  .catch(err => {
    // handle error
    // eg. in express you might do
    //   res.type('application/json')
    //   res.status(500).send({ errors: err })
  })

download options

By default the download promise will resolve with a stream object. If you would prefer, you can instead get back a full buffer of the file like so:

let promise = storage(config).download('my-file.png', {
  type: 'buffer'
})

Image Processing

Version 0.3.0 adds basic image processing, this feature currently adds thumbnail generation and limiting the size of saved images. See following example:

const options = {
  ContentType: 'image/png', // important only works when specified

  maxSize: 1200,            // maximum size in pixels for x and y

  thumbnails: [             // array of image sizes to be generated
    {
      label: '_small',      // will be appended to filename: my-file_small.png
      height: 200,          // image size to generate, specifying only width or height will maintain aspect ratio
      isThumb: true         // identifier flag for thumbnail, should only be set once
    },
    {
      label: '_medium',
      height: 600
    }
  ]
}
storage(config).upload('my-file.png', data, options)
  .then(response => {
    // response will be an array with an element for each size, see below
  })
  .catch(err => {
    // handle any errors
  })

Example Response

[
  {
    "key": "my-file.png",
    "ContentType": "image/png",
    "width": 1200,
    "height": 800
  },
  {
    "key": "my-file_small.png",
    "ContentType": "image/png",
    "width": 300,
    "height": 200,
    "isThumb": true
  },
  {
    "key": "my-file_medium.png",
    "ContentType": "image/png",
    "width": 900,
    "height": 600
  }
]

Providers

Warning: Currently only actively developing for filesystem and AWS, some features may not be supported for pkgcloud providers.

Supports any providers supported by package cloud. See pgkcloud storage for more details.

  • amazon
  • azure
  • hp
  • rackspace
  • openstack
  • google

In addition supports local filestorage

  • filesystem