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

@nmwh917/multer-google-storage

v0.0.0-development

Published

Streaming multer storage engine for Google Cloud Storage

Downloads

3

Readme

multer-google-storage

Travis build

This is a multer storage engine for google's file storage.

Installation

npm install multer-google-storage --save

or

yarn add multer-google-storage

Usage

ES6

import * as  multer from 'multer';
import * as express from 'express';
import MulterGoogleCloudStorage from 'multer-google-storage';

const app = express();

const uploadHandler = multer({
  storage: new MulterGoogleCloudStorage()
});

app.post('/upload', uploadHandler.any(), (req, res) => {
    console.log(req.files);
    res.json(req.files);
});

ES5 / Common.js imports

var multer = require("multer");
var express = require("express");
var multerGoogleStorage = require("multer-google-storage");
var app = express();
var uploadHandler = multer({
    storage: multerGoogleStorage.storageEngine()
});
app.post('/upload', uploadHandler.any(), function (req, res) {
    console.log(req.files);
    res.json(req.files);
});

NB: This package is written to work with es5 or higher. If you have an editor or IDE that can understand d.ts (typescript) type definitions you will get additional support from your tooling though you do not need to be using typescript to use this package.

Google Cloud

Creating a storage bucket

For instructions on how to create a storage bucket see the following documentation from google.

Obtaining credentials

For instructions on how to obtain the JSON keyfile as well a "projectId" (contained in the key file) please refer to the following documentation from google

Credentials

Default method

If using the MulterGoogleCloudStorage class without passing in any configuration options then the following environment variables will need to be set:

  1. GCS_BUCKET, the name of the bucket to save to.
  2. GCLOUD_PROJECT, this is your projectId. It can be found in the json credentials that you generated.
  3. GCS_KEYFILE, this is the path to the json key that you generated.

Explicit method

The constructor of the MulterGoogleCloudStorage class can be passed an optional configuration object.

| Parameter Name | Type | Sample Value | |---|---|---| |autoRetry|boolean| true| |email|string|"[email protected]"| |keyFilename|string|"./key.json"| |maxRetries|number|2| |projectId|string|"test-prj-1234"| |filename| function|(request, file, callback): void| |bucket|string|"mybucketname"| |contentType|function|(request, file): string| |acl|string|"publicread"|

Custom file naming

If you need to customize the naming of files then you are able to provide a function that will be called before uploading the file. The third argument of the function must be a standard node callback so pass any error in the first argument (or null on sucess) and the string name of the file on success.

getFilename(req, file, cb) {
	cb(null,`${uuid()}_${file.originalname}`);
}