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
+16.2k Golang :Trim white spaces from a string
+20k Golang : How to get struct tag and use field name to retrieve data?
+4.7k Golang : A program that contain another program and executes it during run-time
+9.8k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+19k Golang : Check whether a network interface is up on your machine
+9.6k PHP : Get coordinates latitude/longitude from string
+6.2k Golang : Extract sub-strings
+5.6k List of Golang XML tutorials
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+19.7k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+16.3k Golang : How to implement two-factor authentication?
+37k Golang : Converting a negative number to positive number