O'Reilly logo

Go Web Development Cookbook by Arpit Aggarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 along ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required