1.1.0 • Published 4 years ago

multer-sharp-storage v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Multer-Sharp-Storage


Multer-Sharp-Storage is a multer storage engine that allows you to transform the image and store it on the disk.

This project is mostly an integration piece for existing code samples from Multer storage engine documentation. With add-ons include sharp

Installation

npm:

npm install --save multer-sharp-storage

yarn:

yarn add multer-sharp-storage

Tests

npm test

Usage

const express = require('express');
const multer = require('multer');
const sharpStorage = require('multer-sharp-storage');

const app = express();

const storage = sharpStorage({
	output: 'png',
	quality: 90,
	sharpMiddleware: function (sharp) {
		sharp.resize({width: 40, height: 80});
		return sharp;
	},
	destination: function (req, file, cb) {
		cb(null, 'storage/uploads')
	},
	filename: function (req, file, cb) {
		cb(null, file.fieldname + '-' + Date.now())
	}
});

var limits = {
	files: 10,
	fileSize: 1024 * 1024 * 10,
};

const upload = multer({ 
    storage,
    limits
});

app.post('/upload', upload.single('image'), (req, res) => {
    console.log(req.file); // Print upload details
    res.send('Successfully uploaded!');
});

for more example you can see here

Options

const storage = sharpStorage(options);

Multer-Sharp options

optiondefault
outputjpgyour output format
quality70your output quality
destinationstorage/uploadsyour output destination
filenamerandomStringyour output filename

License

MIT Copyright (c) 2019 - forever Kelwin Guevara