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
+17.1k Golang : XML to JSON example
+12.2k Golang : calculate elapsed run time
+7.2k Golang : Check if one string(rune) is permutation of another string(rune)
+13.7k Golang : Tutorial on loading GOB and PEM files
+5.9k Golang : Detect variable or constant type
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+37.5k Golang : Converting a negative number to positive number
+23.1k Golang : Randomly pick an item from a slice/array example
+5.4k Golang : Return multiple values from function
+8.5k Golang : How to check if input string is a word?
+8.2k How to show different content from website server when AdBlock is detected?