Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ const MulterGCS = require('multer-storage')
✗ import MulterGCS from 'multer-storage'
Package uses CommonJS; ESM import may not work. Default export is the factory function.
default
✓ import MulterGCS from 'multer-storage' (if using ESM with bundler)
✗ const { MulterGCS } = require('multer-storage')
Named destructuring fails because the module exports a single function directly, not an object.
default
✓ const multer = require('multer'); const MulterGCS = require('multer-storage')
✗ require('multer-storage')({...}) // Works but misleads on export
The default export is a function, so it can be called immediately, but for clarity define a variable.
Sets up an Express server that accepts file uploads and stores them in Google Cloud Storage using multer-storage.
const express = require('express');
const multer = require('multer');
const MulterGCS = require('multer-storage');
const app = express();
const upload = multer({
storage: MulterGCS({
projectId: process.env.GCLOUD_PROJECT_ID ?? '',
keyFilename: process.env.GCLOUD_KEYFILE ?? '',
bucket: process.env.GCLOUD_BUCKET ?? 'my-bucket',
metadata: (req, file, cb) => cb(null, { contentType: file.mimetype }),
filepath: (req, file, cb) => cb(null, Date.now() + '-' + file.originalname),
acl: 'publicRead'
})
});
app.post('/upload', upload.single('file'), (req, res) => {
res.send(`Uploaded to: ${req.file.path}`);
});
app.listen(3000);
Errors
Common errors & fixes
Error: The bucket property must be provided
Missing or undefined 'bucket' option when calling MulterGCS().
fixEnsure you pass a 'bucket' string in the configuration object.
TypeError: MulterGCS is not a function
Trying to use a named import (e.g., import { MulterGCS } from 'multer-storage') when the module exports a function as default.
fixUse default import: const MulterGCS = require('multer-storage'). Error: No such file or directory, open '/path/to/keyfile.json'
The 'keyFilename' path provided does not exist or is incorrect.
fixProvide an absolute path to a valid service account key JSON file.
Error: Could not load the default credentials
No Google Cloud credentials configured (e.g., missing GOOGLE_APPLICATION_CREDENTIALS environment variable or keyFilename).
fixSet the GOOGLE_APPLICATION_CREDENTIALS env var or provide 'keyFilename' in the configuration.
Audit
Dependencies
@google-cloud/storagerequiredRequired for interacting with Google Cloud Storage API.
multerrequiredPeer dependency; this package provides a storage engine for Multer.