npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multer-flydrive-engine

v1.0.2

Published

A multer storage engine for flydrive's fluent storage interface

Downloads

7

Readme

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.