@platoai/multer-gcs
v1.1.0
Published
Streaming multer storage engine for Google Cloud Storage
Downloads
2
Maintainers
Readme
multer-gcs
Please read the official @google-cloud/storage
documentation for additional options.
Installation
npm install @platoai/multer-gcs
Usage
const multer = require('multer');
const gcs = require('@platoai/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 @platoai/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('@platoai/multer-gcs');
const sox = require('sox-stream');
const storage = gcs({
bucket: 'bucket-name',
transformers: [
() => sox({output: {type: 'wav'}})
],
});