Problem
Solution
Lessons Learned
We can use something like this
<input type="file"
id="upload" name="upload"
accept="image/jpeg,image/png" />
This only shows files of type jpeg
and png
. We can also do image/*
to show all images.
Int to Enum
Assuming we have this enum:
type EnumType int
const (
Zero Enum = iota
One
Two
Three
)
We can convert an int to this type with EnumType(2)
.
Gets the first file in the param (usually POST body).
file, header, err := r.FormFile("upload")
file
can be used like any other file (hint: implements io.Reader
).
header
has info about the file like name and size.
Response.PostForm is a map of url.Values
(map[string][]string
).