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.9k Golang : Get command line arguments
+12.9k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+8.6k Golang : Populate or initialize struct with values example
+19.4k Golang : Measure http.Get() execution time
+11.6k Golang : Clean formatting/indenting or pretty print JSON result
+6.9k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+25.7k Mac/Linux and Golang : Fix bind: address already in use error
+51k Golang : Check if item is in slice/array
+10.6k Nginx : TLS 1.2 support
+20.5k Golang : Convert PNG transparent background image to JPG or JPEG image
+31.7k Golang : Validate email address with regular expression
+8.9k Golang : Create and shuffle deck of cards example