Streaming multer storage engine for Google Cloud Storage
Last updated a year ago by justintimecoder .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install multer-google-storage 
SYNC missed versions from official npm registry.


Travis build

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


npm install multer-google-storage --save


yarn add multer-google-storage



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()
});'/upload', uploadHandler.any(), (req, res) => {

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()
});'/upload', uploadHandler.any(), function (req, res) {

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


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 ""
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

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) {

Current Tags

  • 1.3.0                                ...           latest (a year ago)

15 Versions

  • 1.3.0                                ...           a year ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.0.0-development                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 1
Last Month 20
Dependencies (5)
Dev Dependencies (15)

Copyright 2014 - 2016 © |