@voxjar/multer-gcs

1.1.0 • Public • Published

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

/@voxjar/multer-gcs/

    Package Sidebar

    Install

    npm i @voxjar/multer-gcs

    Weekly Downloads

    2

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • mwilliammyers