multer-sharp-storage
v1.1.0
Published
Multer storage with sharp image processor
Downloads
5
Maintainers
Readme
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