Golang : Get uploaded file name or access uploaded files
A regular community member of Golang Facebook group asked a question recently on how to capture the uploaded filename in a single method. Below is the quick way of getting the filename:
UPDATE:
You can use this method as well to access uploaded files information. Such as the MIME or metadata information.
func uploadHandler(w http.ResponseWriter, r *http.Request) {
file, header, err := r.FormFile("file") // the input file by form
defer file.Close()
if err != nil {
fmt.Fprintln(w, err)
return
}
filename := header.Filename // get the filename
fmt.Fprintf(w,"Filename is" + filename + "\n")
}
Reference :
See also : Golang : Upload file from web browser to server
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+35.5k Golang : Get file last modified date and time
+5.7k Facebook : How to force facebook to scrape latest URL link data?
+4.8k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+15k Golang : How to get Unix file descriptor for console and file
+14.8k Golang : How do I get the local IP (non-loopback) address ?
+10.6k Golang : Command line file upload program to server example
+15.3k Golang : How to convert(cast) IP address to string?
+11.4k Golang : Concurrency and goroutine example
+6k Golang : How to get capacity of a slice or array?
+47.6k Golang : How to convert JSON string to map and slice
+9.9k Golang : Check a web page existence with HEAD request example
+13.2k Facebook PHP getUser() returns 0