Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
/ multer-gcs Public archive
forked from jahmed76/multer-gcs

Multer Storage Engine for Google Cloud Storage

Notifications You must be signed in to change notification settings

voxjar/multer-gcs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 

Repository files navigation

multer-gcs

Multer storage engine for Google Cloud Storage.

Please read the official @google-cloud/storage documentation for additional options.

Installation

npm install @voxjar/multer-gcs

Usage

const multer = require('multer');
const gcs = require('@voxjar/multer-gcs');

const storage = gcs({
  filename: function(req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now());
  },
  bucket: 'bucket-name',
  credentials: require('/path/to/keyfile.json'),
  // optional metadata to add to the file
  metadata: {
    contentType: 'audio/wav'
  },
  // optional, passed to the @google-cloudg/storage `getSignedUrl` method
  // defaults to:
  urlConfig: {
    action: 'read',
    expires: new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000),
  },
  // optional, see: https://cloud.google.com/storage/docs/access-control/lists
  // defaults to:
  acl: 'publicRead',
});

const gcsUpload = multer({storage: storage});

app.post('/upload', gcsUpload.single('file'), function(req, res, next) {
  res.send('File was uploaded successfully!');
});

configuration

You can also use environment variables for @voxjar/multer-gcs parameters.

GCS_BUCKET='bucket-name'
GCLOUD_PROJECT='dummy-project'
GOOGLE_APPLICATION_CREDENTIALS='/path/to/keyfile.json'

All the official @google-cloud/storage authentication options should be supported by the gcs method. For more information, read their documentation.

transformers

You can also pass an array of functions that return anything that implements the streaming interface and they will be applied before uploading the file to Google Cloud Storage.

const gcs = require('@voxjar/multer-gcs');
const sox = require('sox-stream');

const storage = gcs({
  bucket: 'bucket-name',
  transformers: [
    () => sox({output: {type: 'wav'}})
  ],
});

License

MIT

About

Multer Storage Engine for Google Cloud Storage

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%