Handling HTTP uploaded files and forms as a stream
The standard library provides methods to deal with file uploads. You can call http.Request.ParseMultipartForm
, and work with uploaded files. There is one problem with this approach: ParseMultipartForm
processes all uploads up to a given memory limit. It may even use temporary files. This is not a scalable approach if you are dealing with large files. This section describes how you can work with file uploads without creating temporary files or a large memory footprint.
How to do it...
On the client side, do the following:
- Create an HTML form with
multipart/form-data
encoding. - Add the form fields and files that you are planning to upload.
An example is given here:
<form action="/upload" method="post" enctype="multipart/form-data"> <input type="text" name="textField"> <input type="file" name="fileField"...