question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resize with Sharp.js

See original GitHub issue

I want to upload images using multer, and resize them on save with sharp.js. Has anybody tried to use them both? Google is empty

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
LinusUcommented, Apr 30, 2015

Should be really easy!

var express = require('express')
var multer  = require('multer')
var sharp = require('sharp')

var app = express()
app.use(multer({ dest: './uploads/'}))

app.post('/upload', function (req, res, next) {
  sharp(req.files['image'].path).resize(200, 200).toBuffer(function (err, buf) {
    if (err) return next(err)

    // Do whatever you want with `buf`
  })
})
2reactions
wesboscommented, Mar 3, 2017

If anyone is reading this the above code should not be used - taken from the multer docs:

WARNING: Make sure that you always handle the files that a user uploads. Never add multer as a global middleware since a malicious user could upload files to a route that you didn’t anticipate. Only use this function on routes where you are handling the uploaded files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resizing images - High performance Node.js image processing
Resize large images in common formats to smaller, web-friendly JPEG, PNG, WebP, GIF and AVIF images of varying dimensions.
Read more >
How To Process Images in Node.js With Sharp - DigitalOcean
First, you'll chain the resize() method from the sharp instance to resize the image, and save it in the project directory. Second, you'll...
Read more >
lovell/sharp - GitHub
High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.
Read more >
How to resize an image in sharp with the option 'contain' but ...
I realize it is possible to do this by specifying only a width. However it is useful to have a bounding box to...
Read more >
Resize an image in Node.js using Sharp - YouTube
Just a few examples of how you could resize images in Node. js using the Sharp package.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found