Golang net/http.Request.MultipartReader() function example
package net/http
Golang net/http.Request.MultipartReader() function usage example
func uploadProgress(w http.ResponseWriter, r *http.Request) {
mr, err := r.MultipartReader()
if err != nil {
fmt.Fprintln(w, err)
return
}
length := r.ContentLength
//ticker := time.Tick(time.Millisecond) // <-- use this in production
ticker := time.Tick(time.Second) // this is for demo purpose with longer delay
for {
var read int64
var p float32
part, err := mr.NextPart()
...
see full example at https://www.socketloop.com/tutorials/golang-upload-receive-file-progress-indicator
References :
Advertisement
Something interesting
Tutorials
+14.6k Golang : Reset buffer example
+9.6k Golang : Validate IPv6 example
+5.4k Unix/Linux : How to archive and compress entire directory ?
+10.4k Golang : Meaning of omitempty in struct's field tag
+18.6k Golang : Iterating Elements Over A List
+7.9k Golang : Ways to recover memory during run time.
+4.7k Golang : How to pass data between controllers with JSON Web Token
+10.4k Golang : cannot assign type int to value (type uint8) in range error
+4.8k Which content-type(MIME type) to use for JSON data
+30.4k Golang : Generate random string
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+18.5k Golang : Aligning strings to right, left and center with fill example