How to do it...

In this recipe, we are going to create an HTML form with a field of type file, which lets the user pick one or more files to upload to a server via a form submission. Perform the following steps:

  1. Create upload-file.html inside the templates directory, as follows:
$ mkdir templates && cd templates && touch upload-file.html
  1. Copy the following content to upload-file.html:
<html>  <head>    <meta charset="utf-8">    <title>File Upload</title>  </head>  <body>    <form action="/upload" method="post" enctype="multipart/    form-data">      <label for="file">File:</label>      <input type="file" name="file" id="file">      <input type="submit" name="submit" value="Submit">    </form>  </body></html>

In the preceding template, we defined a field of type file

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.