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

skipper-gcstorage

v2.3.1

Published

A skipper adapter used for uploading files to Google Cloud Storage

Downloads

446

Readme

Google Cloud Storage Blob Adapter

npm GitHub release (latest by date) NPM

Google Cloud Storage adapter for receiving upstreams. Particularly useful for handling streaming multipart file uploads from the Skipper body parser.

Installation

Option 1: NPM Package

NPM

$ npm i skipper-gcstorage

Option2: GitHub Package

GitHub

$ npm i @chenglongma/skipper-gcstorage

Changelog

Ver 2.3.0

  1. Add keepName option which can set whether to use original filename or a generated UUID name.
  2. Update dependencies to the latest version.

Ver 2.2.0

  1. Update dependencies to the latest version.
    1. sharp: 0.29.2, now it supports M1 chipset ( thanks lahiruelectrily (github.com))
    2. mime: 3.0.0

Ver 2.1.0

Thanks jspark-gigworks (Anselmo Park) so much for his comments!

  1. Emit writefile event when finishing the job.
  2. Support additional CreateWriteStreamOptions listed in https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions.

Ver 2.0.0

  1. Add resize options, which can compress the images before uploading.

Usage

req.file('avatar')
    .upload({
        // Required
        adapter: require('skipper-gcstorage'),
        bucket: 'existing_or_new_bucket_name', // Will create new one if no such bucket exists.
        // Optional
        projectId: 'GOOGLE_CLOUD_PROJECT', // Mandatory if `keyFilename` was specified.
        keyFilename: '/path/to/GOOGLE_APPLICATION_CREDENTIALS.json',
        bucketMetadata: {
            location: 'us-west1',
        },  // Refer to https://googleapis.dev/nodejs/storage/latest/global.html#CreateBucketRequest
        maxBytes: 60000,
        metadata: {},
        public: true,
        gzip: true,
        keepName: false,
        // Other options in `CreateWriteStreamOptions`
        // Refer to https://googleapis.dev/nodejs/storage/latest/global.html#CreateWriteStreamOptions
        ...CreateWriteStreamOptions,
        resize: {
            width: 500,
            height: 500
        }, // Refer to https://sharp.pixelplumbing.com/api-resize#resize
    }, function whenDone(err, uploadedFiles) {
        if (err) {
            return res.serverError(err);
        }
        return res.ok({
            files: uploadedFiles,
            textParams: req.params.all()
        });
    });

Please don't check in your GCP credentials :)

Parameters

| Name | Type | Required | Default Value | Description | |-----------------------------|-------------------------------------------|-----------------------------------|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | bucket | string | Yes | None | Bucket name in GCP, will create new one if there is no such bucket. | | projectId | string | Yes if keyFilename is specified | None, will try to read process.env.GOOGLE_CLOUD_PROJECT if not set | "GOOGLE_CLOUD_PROJECT", please refer to Google Cloud Storage#using-the-client-library | | keyFilename | string | No | None, will try to read process.env.GOOGLE_APPLICATION_CREDENTIALS if not set | "/path/to/GOOGLE_APPLICATION_CREDENTIALS.json" | | bucketMetadata | dictionary | No | {} | Metadata to set for the bucket. Refer to Google Cloud Storage#CreateBucketRequest | | metadata | dictionary | No | {} | Extra info attached to the file | | public | boolean | No | true | Whether to make the file public | | keepName | boolean or string | No | false | Whether to use original filename. The uploaded file will be set to: * a UUID name if keepName=false; * its original name if keepName=true; * the value of keepName if keepName is a string | | ...CreateWriteStreamOptions | expanded dictionary | No | {} | Options for File#createWriteStream(). Refer to Google Cloud Storage#CreateWriteStreamOptions | | resize | dictionary with keys width and height | No | {} | The new size of image. Only works when the file is an image. Refer to sharp#resize. |

NOTE

  1. Skipper-GCStorage will create new bucket if specified one does not exist.
    1. Assign bucket metadata into bucketMetadata.
  2. Support multiple ways for Authentication
    1. Specify projectId AND keyFilename;
    2. export GOOGLE_APPLICATION_CREDENTIALS environment variable;
    3. Login with an eligible service account;
    4. *For more details, please refer to https://cloud.google.com/docs/authentication/production#command-line.
  3. Use with sails-hook-uploads for better results :)
  4. Cloud Storage operates with a flat namespace, which means that folders don't actually exist within Cloud Storage. If you create an object named folder1/file.txt in the bucket your-bucket, the path to the object is your-bucket/folder1/file.txt, but there is no folder named folder1; instead, the string folder1 is part of the object's name. Please refer to https://cloud.google.com/storage/docs/folders

Acknowledgement

  1. Sails Skipper
  2. Skipper-S3
  3. jspark-gigworks (Anselmo Park)

Contribution

Pull requests are welcome!