1 | # multer-s3
|
2 | Streaming multer storage engine for AWS S3
|
3 |
|
4 | This 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.
|
5 |
|
6 | # Install
|
7 | ```
|
8 | npm install --save multer-s3
|
9 | ```
|
10 |
|
11 | # Tests
|
12 | Tested with [s3rver](https://github.com/jamhall/s3rver) instead of your actual s3 credentials. Doesn't require a real account or changing of hosts files. Includes integration tests ensuring that it should work with express + multer.
|
13 |
|
14 | ```
|
15 | npm test
|
16 | ```
|
17 |
|
18 | # Usage
|
19 | ```
|
20 | var express = require('express');
|
21 | var app = express();
|
22 | var multer = require('multer');
|
23 | var s3 = require('multer-s3');
|
24 |
|
25 | var upload = multer({
|
26 | storage: s3({
|
27 | dirname: 'uploads/photos',
|
28 | bucket: 'some-bucket',
|
29 | secretAccessKey: 'some secret',
|
30 | accessKeyId: 'some key',
|
31 | region: 'us-east-1'
|
32 | })
|
33 | })
|
34 |
|
35 | app.post('/upload', upload.array('photos', 3), function(req, res, next){
|
36 | res.send('Successfully uploaded!');
|
37 | });
|
38 | ```
|