# multer-storage-s3

> AWS S3 Multer Storage Engine

Latest version **1.1.1** (published 2016-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install multer-storage-s3
pnpm add multer-storage-s3
yarn add multer-storage-s3
bun add multer-storage-s3
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2016-01-12 |
| First published | 2015-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 16 |
| Author | originalexe |
| Maintainers | originalexe |
| Keywords | multer, s3, aws, amazon, node.js |

## Links

- npm: https://www.npmjs.com/package/multer-storage-s3
- Repository: https://github.com/OriginalEXE/Multer-Storage-S3
- Homepage: https://github.com/OriginalEXE/Multer-Storage-S3#readme
- Issues: https://github.com/OriginalEXE/Multer-Storage-S3/issues
- npm.io page: https://npm.io/package/multer-storage-s3

## Dependencies (4)

- [path](https://npm.io/package/path.md) ^0.12.7
- [crypto](https://npm.io/package/crypto.md) 0.0.3
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.2.28
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.9

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2016-01-12
- 1.1.0 — 2015-10-11
- 1.0.2 — 2015-10-06
- 1.0.1 — 2015-09-12
- 1.0.0 — 2015-09-12

## README

# Multer-Storage-S3
AWS S3 Multer Storage Engine

Multer Storage Engine that uses Amazon S3 as a storage system. Uses an offical AWS SDK.

## Installation
	
	npm install multer-storage-s3
	
## Dependencies
* aws-sdk - for communication with the S3
* crypto  - for generating a psudo random filename if one is not provided
* path    - for precise paths handling

## Usage
Multer-Storage-S3 follows the naming convention set by an existing DiskStorage storage engine that comes with multer.
```
var multer = require( 'multer' );
var s3 = require( 'multer-storage-s3' );
var storage = s3({
	destination : function( req, file, cb ) {
		
		cb( null, 'multer-uploads/my-files' );
		
	},
	filename    : function( req, file, cb ) {
		
		cb( null, file.fieldname + '-' + Date.now() );
		
	},
	bucket      : 'bucket-name',
	region      : 'us-west-2'
});
var uploadMiddleware = multer({ storage: storage });

app.post( '/upload', uploadMiddleware.single( 'attachment' ), function( req, res, next ) {

	res.send( 'File was uploaded successfully!' );

});
```

You will notice that we have not specified our AWS `access key` or `secret access key`. This is because you can't pass your AWS credentials directly to the Multer-Storage-S3. It would be pretty dangerous to have those credentials written in the code that you will most likely store on GitHub or some other repository. Instead, you should set those parameters as an environment variables.

The easiest way to do that is to use a `dotenv` npm package in your project (as soon as possible):

	require( 'dotenv' ).load();
	
Then, simply create an .env file in your project directoy, and add this:
```
AWS_ACCESS_KEY_ID=XXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=YYYYYYYYYYYY
```

Of course, you can export environment variables globally as well, this is just a more handy way. Make sure you add .env file to your `.gitignore` as you do not want to store that file on the repo.

If you want, you can also define your bucket, as well as your region through environment variables:
```
AWS_REGION=us-west-2
S3_BUCKET=bucket-name
```

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/multer-storage-s3 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
