New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

multer-aws-s3

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multer-aws-s3

AWS S3 storage engine for multer

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-62.5%
Maintainers
1
Weekly downloads
 
Created
Source

multer-aws-s3

AWS S3 storage engine for multer.

Installation

$ npm install --save multer-aws-s3

Basic Usage

var multer = require('multer')
var AWS = require('aws-sdk')
var S3Storage = require('multer-aws-s3')

// AWS setup here...

var upload = multer({
  storage: new S3Storage({
    basepath: '/remote/path',
    s3: new AWS.S3({ params: { Bucket: 'myBucket' } })
  })
})

Different filenames

By default random filenames are chosen (crypto.randomBytes), you can change this behavior however by using a custom destination function:

// Demonstrates destination that uses sha1 digest of file
var multer = require('multer')
var crypto = require('crypto')
var AWS = require('aws-sdk')
var S3Storage = require('multer-aws-s3')

var upload = multer({
  storage: new S3Storage({
    destination: function (req, file, options, callback) {
      var digest = crypto.createHash('sha1')

      digest.setEncoding('hex')

      file.stream.pipe(digest)

      file.stream.on('end', function () {
        digest.end()
        callback(null, digest.read())
      })
    },
    s3: new AWS.S3({ params: { Bucket: 'myBucket' } })
  })
})

Advanced usage

var multer = require('multer')
var AWS = require('aws-sdk')
var S3Storage = require('multer-aws-s3')

var upload = multer({
  storage: new S3Storage({
    basepath: '/remote/path', // base path for keys in the bucket
    s3: new AWS.S3({ params: { Bucket: 'myBucket' } }), // `aws-sdk` S3 instance
    destination: function (req, file, options, callback) {
      callback(null, 'testfilename') // custom file destination, file extension is added to the end of the path
    },
    transformFile: function (req, file, callback) {
      // transform the file before uploading it
      //   file.stream is a ReadableStream of the file
      //   callback(error, < ReadableStream | Buffer | String >)
      callback(null, file.stream)
    }
  })
})

Todo

Write tests

License

MIT

Keywords

FAQs

Package last updated on 16 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc