File uploads are a special type of POST request and handling them is not completely trivial. In this video, learn how to implement a file upload form.
- [Instructor] So far we can receive the form data now…when the form is posted.…How can we make sure that it's complete,…and also doesn't contain malicious data?…Of course we could take a few measures within HTML…that means on the client side.…For instance, if we add the required attribute…to a form field, the form can only be sent…if this field is filled out.…This would work for most browsers today,…and would solve the problem of…users not filling out the form completely by mistake.…But what if we had a bad actor?…I can send a post request basically from a comment line,…so there is no browser involved.…
A bad actor could still send us empty forms.…This means you can never trust the client side,…and we need measures on the server side…to make sure that the data we process is valid.…Let's do that now in our feedback post route.…So what I want to do now,…is making sure that the user has filled out all fields.…And for that I will now…add const fbName…equals req.body….fbName,…and now important I add trim to it to make sure…
- Creating a server with Express and pure Node.js
- Handling errors in Express
- Creating routes
- Using templates
- Working with the Pug template engine
- Implementing the site structure and logic
- Working with conditionals
- Dealing with POST requests
- Sanitizing user inputs and handling form errors
Skill Level Beginner
What you should know1m 40s
1. Getting Started
2. Express Basics
3. Getting Started with Our Project
4. Getting Started with Templates
5. Implementing the Site Structure and Logic
6. Handling Form Data
- 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.Cancel
Take 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.