Streaming multer storage engine for AWS S3.
This project is mostly an integration piece for existing code samples from Multer's storage engine documentation with s3fs as the substitution piece for file system. Existing solutions I found required buffering the multipart uploads into the actual filesystem which is difficult to scale.
npm install --save multer-s3
var aws = require('aws-sdk')
var express = require('express')
var multer = require('multer')
var multerS3 = require('multer-s3')
var app = express()
var s3 = new aws.S3({ /* ... */ })
var upload = multer({
storage: multerS3({
s3: s3,
bucket: 'some-bucket',
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
})
app.post('/upload', upload.array('photos', 3), function(req, res, next) {
res.send('Successfully uploaded ' + req.files.length + ' files!')
})
Each file contains the following information exposed by multer-s3
:
Key | Description | Note |
---|---|---|
size |
Size of the file in bytes | |
bucket |
The bucket used to store the file | S3Storage |
key |
The name of the file | S3Storage |
contentType |
The mimetype used to upload the file |
S3Storage |
location |
The S3 url to access the file |
S3Storage |
etag |
The etag of the uploaded file in S3 |
S3Storage |
The tests mock all access to S3 and can be run completely offline.
npm test