UNPKG

1.15 kBMarkdownView Raw
1# Multer S3
2
3Streaming multer storage engine for AWS S3.
4
5This project is mostly an integration piece for existing code samples from Multer's [storage engine documentation](https://github.com/expressjs/multer/blob/master/StorageEngine.md) with [s3fs](https://github.com/RiptideElements/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.
6
7## Installation
8
9```sh
10npm install --save multer-s3
11```
12
13## Usage
14
15```javascript
16var aws = require('aws-sdk')
17var express = require('express')
18var multer = require('multer')
19var multerS3 = require('multer-s3')
20
21var app = express()
22var s3 = new aws.S3({ /* ... */ })
23
24var upload = multer({
25 storage: multerS3({
26 s3: s3,
27 bucket: 'some-bucket',
28 key: function (req, file, cb) {
29 cb(null, Date.now().toString())
30 }
31 })
32})
33
34app.post('/upload', upload.array('photos', 3), function(req, res, next) {
35 res.send('Successfully uploaded ' + req.files.length + ' files!')
36})
37```
38
39## Testing
40
41The tests mock all access to S3 and can be run completely offline.
42
43```sh
44npm test
45```