HTML & CSS Interview Question #44

What is multipart/form-data and when is it required?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Mid-Level Intermediate

Quick Interview Answer

multipart/form-data is a form encoding type designed to send multiple parts in one request, including binary file content. It is required for a traditional HTML form that uploads files through an input with type="file".

Detailed Explanation

multipart/form-data is a form encoding type designed to send multiple parts in one request, including binary file content. It is required for a traditional HTML form that uploads files through an input with type="file".

The form should use method="post" and enctype="multipart/form-data". The server must still validate file size, type, content, storage location, permissions, and other security requirements.

Code Example

<form action="/resume/upload"
      method="post"
      enctype="multipart/form-data">

    <label for="resume">Resume</label>
    <input id="resume"
           name="resume"
           type="file"
           accept=".pdf,.docx">

    <button type="submit">Upload</button>
</form>