Once a file is received, it needs to be stored somewhere. This video shows how to store it in the file system.
- [Narrator] By now, we have a buffer…that contains our image data…and some meetup information for the image.…In this video, we will convert the image to PNG,…to not having to deal with different file formats,…and we shrink the image to a maximum size needed…on our page to save some disk space.…There are several modules that deal…with image manipulation available;…I personally prefer sharp.…It provides plenty of image manipulation methods…and a good performance.…So let's install it now by running npm install --save sharp,…and we will need image manipulation functions…on different places,…so it makes sense to create this service class for that.…
So I will now go into server, services,…and there I create a new file: AvatarService.js.…There, of course, first,…bring const sharp = require('sharp'),…and we need need a few more modules,…because I want to automatically create file names.…For that, we will use uuidv4 = require('uuid'),…and we take the version four here,…and we need util,…and also we will need path to deal with file path,…
Author
Released
2/7/2019- Creating a template engine
- Using MongoDB and Mongoose for user management
- Authenticating and authorizing users
- Adding cookies and sessions to Express
- Creating a login form with Passport
- Handling file uploads
- Storing and serving images
- Deploying an Express application
- Securing an Express application
- Running behind a web server
Skill Level Advanced
Duration
Views
Related Courses
-
Building RESTful Web APIs with Node.js and Express
with Emmanuel Henri1h 40m Intermediate -
Advanced Node.js
with Alex Banks2h 3m Intermediate -
Advanced Node.js: Scaling Applications
with Alex Banks1h 15m Advanced
-
Introduction
-
What you should know1m 20s
-
Get your tools ready2m 1s
-
1. Know the Building Blocks and Internals of Express
-
Important Express middleware1m 27s
-
2. Use MongoDB and Mongoose to Manage Users
-
Connecting to MongoDB3m 27s
-
3. Authenticate and Authorize Users
-
Introduction to Passport1m 39s
-
Adding Passport to Express3m 55s
-
Providing a logout link2m 1s
-
Protecting routes3m 35s
-
4. Handle File Uploads and Process Images
-
File upload basics3m 9s
-
Serving images6m 32s
-
-
5. Deployment and Running in Production
-
Add logging5m 3s
-
Conclusion
-
Next steps44s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Resizing and storing images with sharp