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

gcloud-storage-api

v1.2.2

Published

A wrapper around the google storage functions for upload (both upload and streaming) and delete.

Downloads

11

Readme

gcloud-storage-api

An easy google storage tool to upload file and generate public link as return (both file uploading and buffer streaming).

A wrapper base on gcloud, which around the google storage functions for upload (both file uploading and streaming) and delete.NPM

Install

$ npm install --save gcloud-storage-api

Functions of this package:

googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath)
googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer)
googleAPI.deleteStorageFile(url)

Usage

To get the projectId and key.json, it is needed to Visit the Google Developers Console. There is the offical instruction from gcloud: https://www.npmjs.com/package/gcloud

Initialization

Create a service account key on Google Cloud Console:

alt tag

Key type, select JSON, and then a service-key.json is generated and able to download:

alt tag

Paste the service-key to root of NODE project

alt tag

service-key.json

alt tag

Initializing gcloud

var googleAPI = require('gcloud-storage-api')
googleAPI.init('projectId',"service-key.json")

Upload local file

  • googleAPI.formParsing is a fomidable function which parsing local file with POST is multipart
  • googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath) is a function that does local file uploading, respose the public link and resolve a promise.
## Usage
app.post('/upload', googleAPI.formParsing, function(req, res, next) {

    var fileName = "path/to/"+req.uploadFile.name
    var fileLocalPath  = req.uploadFile.path
    var BUCKET_NAME = "yourbucket"

    googleAPI.uploadLocalFile(BUCKET_NAME, fileName, fileLocalPath).then(function(result) {
        console.log("finished uploadLocalFile: "+result)
        res.send(result)
    },function(err){
        console.log(err)
    })
});

Upload Streaming/Buffer

  • fileName = "path/to/upload/abc.file"
  • googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer) is a function that does buffer uploading, respose the public link and resolve a promise.
app.post('/streamupload', googleAPI.formParsing, function(req, res, next) {

    var fileName = "path/to/"+req.uploadFile.name
    var fileLocalPath  = req.uploadFile.path
    var BUCKET_NAME = "peterbucket"

    fs.readFile(fileLocalPath,function(err, buffer){
        googleAPI.uploadBuffer(BUCKET_NAME, fileName, buffer).then(function(result) {
            console.log("after googleAPI.deleteDownloadableFile: "+result)
            res.send(result)
        })
    })
});

Delete storage file

  • url = "https://storage.googleapis.com/yourbucket/path/to/upload/abc.file"
  • googleAPI.deleteStorageFile(url) is a function that deletes file on google storage.
app.post('/delete', function(req, res, next) {
    var url = req.query.url
    googleAPI.deleteStorageFile(url).then(function(result) {
        console.log("after googleAPI.deleteStorageFile: "+result)
        res.send(result)
    })
});

License

MIT