Skip to content

kguevara/multer-sharp-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

option default
output jpg your output format
quality 70 your output quality
destination storage/uploads your output destination
filename randomString your output filename

License

MIT Copyright (c) 2019 - forever Kelwin Guevara

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published