heya everyone: Got a short question, I would like to post(http) a file. I figured, since os.Open returns an io.Reader and http.Post takes an io.Reader I do not have read the file into memory in a separate step and can just pass around the Reader. However, the Content-Length will be set to zero- which kinda makes sense but is not what I need.
file, _ := os.Open("some file")
req, _ := http.NewRequest("POST", "some url", file)
dump, _ := httputil.DumpRequestOut(req, false)
fmt.Println(string(dump))
My question: Do i have to read the file into memory (with ioutil.ReadFile or some such) and make a new reader or is there a way to pass the reader from the file directly to the Post request without the "Reading" step?
I guess I could set the Content-Length by getting it via file.Stat, but I was wondering if there is a more elegant way of doing this?