Golang mime/multipart.FileHeader.Open() function example
package mime/multipart
Golang mime/multipart.FileHeader.Open() function usage example
formdata := r.MultipartForm // ok, no problem so far, read the Form data
//get the *fileheaders
fileHeaders := formdata.File["multiplefiles"] // grab the filenames
for i, _ := range fileHeaders { // loop through the files one by one
file, err := fileHeaders[i].Open() // <--------------------- here!
defer file.Close()
if err != nil {
fmt.Fprintln(w, err)
return
}
w.Write([]byte(fmt.Sprintf("Filename : %s open successfully.", fileHeaders[i].Filename)))
}
References :
https://www.socketloop.com/tutorials/upload-multiple-files-golang
Advertisement
Something interesting
Tutorials
+9.8k Golang : Get current, epoch time and display by year, month and day
+23.5k Golang : Read a file into an array or slice example
+15.8k Golang : How to login and logout with JWT example
+6k Javascript : Get operating system and browser information
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+5.6k Javascript : How to refresh page with JQuery ?
+7.5k Golang : Rot13 and Rot5 algorithms example
+30.6k Golang : Remove characters from string example
+11.1k Golang : Read until certain character to break for loop
+5k Linux : How to set root password in Linux Mint
+8.5k Linux/Unix : fatal: the Postfix mail system is already running