Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render uploaded photos with NodeJS and Express?

I generally post examples of my best shot at what I'm asking about, but in this case, I have no idea where to start (haven't uploaded photos before in other languages).

So how does one go about rendering uploaded photos. I'm using Node v0.4.2, Express 1.0.8, and Mongoose 1.0.16 and have uploading of images working (they end up in ~/tmp right now).

Thanks.

like image 762
JohnAllen Avatar asked Mar 11 '11 02:03

JohnAllen


People also ask

How do I upload an image to Express?

Open the local page http://127.0.0.1:2000/ to upload the images. Select an image to upload and click on "Upload Image" button. Here, you see that file is uploaded successfully. You can see the uploaded file in the "Uploads" folder.

Is Node JS good for image processing?

With image processing, your application can resize and compress all the user-uploaded images, which can significantly improve your application performance and save your server disk space. Node. js has an ecosystem of libraries you can use to process images, such as sharp, jimp, and gm module.


1 Answers

If you just want to render thumbnail versions of your uploaded images for display, try using the imagemagick wrapper node-imagemagick.

For example, you could store your hires-images in a data-folder on your server (lets say /data/images) and render thumbnail images into a web-accessible folder (on upload).

I do not recommend generating the thumbnails on the fly, as it can massively increase your server's load when a large image (especially vector formats like eps or pdf) is being rendered.

For imagemagick examples, consider reading up the docs for the convert command.

like image 189
schaermu Avatar answered Oct 03 '22 16:10

schaermu