Uploading your first file
One of the most common scenarios in any web application is uploading a file or a folder to the server. For example, if we are developing a job portal, then we may have to provide an option where the applicant can upload their profile/resume, or, let's say, we have to develop an e-commerce website with a feature where the customer can upload their orders in bulk using a file.
Achieving the functionality to upload a file in Go is quite easy using its built-in packages, which we will be covering in this recipe.
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:
- Create
upload-file.html
inside thetemplates
directory, as follows:
$ mkdir templates && cd templates && touch upload-file.html
- Copy the following content to
upload-file.html
:
<html> <head> <meta charset="utf-8"> ...