Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

multer-flydrive-engine

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multer-flydrive-engine

A multer storage engine for flydrive's fluent storage interface

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

multer-flydrive-engine

A multer storage engine for flydrive's fluent storage interface

The flydrive storage engine gives you full control on storing files to whatever backing storage service you choose to configure through flydrive.

var storage = new StorageManager({
  disks: {
    local: {
      driver: 'local',
      root: process.cwd(),
    },
    s3: {
      driver: 's3',
      key: 'AWS_S3_KEY',
      secret: 'AWS_S3_SECRET',
      region: 'AWS_S3_REGION',
      bucket: 'AWS_S3_BUCKET',
	}
  }
});

var storageEngine = FlydriveStorageEngine({
  async disk (req, file) {
    return req.query.dest === 's3' ? storage.disk('s3') : storage.disk('local');
  },
  async destination (req, file) {
    return '/tmp/my-uploads';
  },
  async filename (req, file, cb) {
    return file.fieldname + '-' + Date.now();
  }
});

var upload = multer({ storage: storageEngine });

The disk attribute is required, and there are two options available,destination and filename. They are all functions that determine where the file should be stored.

disk is used to determine which flydrive disk on which to store the file. This can also be given as a single flydrive storage disk (e.g. storage.disk()).

destination is used to determine within which folder the uploaded files should be stored. This can also be given as a string (e.g. '/tmp/uploads'). If no destination is given, the disk's configured root directory is used. Since the underlying engine is flydrive, you do not need to worry about directory creation, flydrive will handle this for you.

filename is used to determine what the file should be named inside the folder. If no filename is given, each file will be given a random name that doesn't include any file extension.

Note: Multer will not append any file extension for you, your function should return a filename complete with an file extension.

Each function gets passed both the request (req) and some information about the file (file) to aid with the decision.

Note that req.body might not have been fully populated yet. It depends on the order that the client transmits fields and files to the server.

Keywords

FAQs

Package last updated on 09 Mar 2020

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