Registry / storage / multer-storage-s3

multer-storage-s3

JSON →
library1.1.1jsnpmunverified

Multer storage engine for uploading files to AWS S3 using the official AWS SDK. Version 1.1.1 is the latest stable release, with no active development since 2018. It provides a familiar API similar to multer's DiskStorage, supporting destination and filename callbacks. Credentials are handled via environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) to avoid hardcoding. Compared to alternatives like multer-s3, this package has fewer features but simpler usage. It requires Node.js and peer dependencies: multer, aws-sdk, crypto, and path.

npm install multer-storage-s3
INSTALL
IMPORT
SIG · MULTER-STORAGE-S3
M
multer-storage-s3
storagejavascriptv1.1.1
harness data pending
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
import s3 from 'multer-storage-s3'
const s3 = require('multer-storage-s3')
CommonJS require works, but ESM import is preferred for modern Node.js (>=12).
default
const s3 = require('multer-storage-s3')
import { s3 } from 'multer-storage-s3'
The package exports a single function as default export. Named import is incorrect.
storage options object
const storage = s3({ bucket: 'my-bucket', region: 'us-east-1' })
const storage = new s3({ bucket: 'my-bucket' })
s3 is a factory function, not a constructor. Do not use 'new'.

Express server with multer and multer-storage-s3 to handle single file upload to S3. Uses environment variables for credentials.

import multer from 'multer'; import s3 from 'multer-storage-s3'; import express from 'express'; const app = express(); const storage = s3({ destination: (req, file, cb) => { cb(null, 'uploads/'); }, filename: (req, file, cb) => { cb(null, Date.now() + '-' + file.originalname); }, bucket: process.env.S3_BUCKET ?? '', region: process.env.AWS_REGION ?? 'us-east-1' }); const upload = multer({ storage }); app.post('/upload', upload.single('file'), (req, res) => { res.send('File uploaded successfully'); }); app.listen(3000);
Debug
Known issues
gotchaAWS credentials must be set via environment variables; cannot pass directly to the engine.
fix
Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables, e.g., using dotenv.
affects: >=0.0.0
deprecatedThe package uses aws-sdk v2 which is in maintenance mode; consider migrating to aws-sdk v3 or using multer-s3 with S3Client.
fix
Switch to @aws-sdk/client-s3 and use multer-s3 or custom middleware.
affects: >=1.0.0
gotchaThe destination callback does not accept S3 key prefix; it sets the S3 object key directly without a leading slash.
fix
Ensure destination returns a relative path like 'folder/file.ext', not an absolute path.
affects: >=0.0.0
gotchaUsing require('multer-storage-s3') does not work in ESM; must use dynamic import or named import.
fix
Use import s3 from 'multer-storage-s3' in ESM projects.
affects: >=1.0.0
breakingVersion 1.0.0 changed from synchronous to asynchronous destination/filename callbacks.
fix
Update callbacks to accept (req, file, cb) and call cb(null, value).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: s3 is not a constructor
Trying to instantiate the module with 'new s3()'.
fix
Remove 'new'; call s3({...}) as a factory function.
Error: The AWS Access Key Id you provided does not exist in our records.
Missing or incorrect AWS_ACCESS_KEY_ID environment variable.
fix
Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY via environment variables.
Cannot find module 'multer-storage-s3'
Package not installed or using wrong import path.
fix
Run 'npm install multer-storage-s3' and import using 'const s3 = require('multer-storage-s3')' or 'import s3 from 'multer-storage-s3''.
Error: The bucket you are attempting to access must be addressed using the specified endpoint.
Incorrect S3 region or bucket name.
fix
Ensure the region and bucket name are correct in the options or environment variables.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
aws-sdkrequiredCore dependency for Amazon S3 communication
cryptorequiredGenerates random filenames if not provided
pathrequiredHandles file path manipulation
Agent activity
16 hits · last 30 days
node
14
Resources
multer-storage-s3 — npm install multer-storage-s3 · libregistry