As Bruno said. Try something like this:
func uploadBig(url string ) error { file, err := os.Open("bigfile.txt") if err != nil { return err } defer file.Close() resp, err := http.Post(url, "text/plain", file) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode >= 400 { return fmt.Errorf("Bad Status %s", resp.Status) } _, err = io.Copy(os.Stdout, resp.Body) return err } On Monday, 6 March 2023 at 15:17:36 UTC Bruno Albuquerque wrote: The body is just an io.Reader. You just need to write one that materializes and streams the data you want instead of using a buffer with all of it. The entire design is to allow things like what you want to do. :) -Bruno On Mon, Mar 6, 2023 at 10:08 AM 'Jim Smart' via golang-nuts < golan...@googlegroups.com> wrote: Hi all, I'm looking for an HTTP client that allows my code to write the body content down the pipe while doing a POST. The use case here is that I'm wishing to send very large UPDATE/INSERT queries/commands to an HTTP endpoint, and the body content of those queries/commands is actually generated from a database. So it would be better, memory- and performance- wise, if I could write that straight down the pipe during the request, as opposed to manifesting the whole of the query/command into a buffer before doing the POST. Is this possible at all with the stdlib http.Client? Perhaps with an io.Pipe as the request body? I did look at the code for http.Client a little, but there's a lot of it, and it's not the simplest of code to follow. I do have a base understanding of the HTTP 1.1 protocol, but there's a lot more to http.Client than just that, of course. I've also tried looking for existing examples showing similar functionality, but did not seem to find anything. Which is partly what makes me wonder if perhaps the stdlib http.Client cannot operate like this. If I can't do this with the stdlib http.Client, and I have to roll-my-own client of sorts, are there any parts of the existing http package that I should be making use of? Any tips / pointers / info greatly appreciated. Thanks, /Jim -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/545d0597-66a0-4412-8ca7-3d447f88ccafn%40googlegroups.com <https://groups.google.com/d/msgid/golang-nuts/545d0597-66a0-4412-8ca7-3d447f88ccafn%40googlegroups.com?utm_medium=email&utm_source=footer> . -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d9e4e00f-2251-453c-88f2-5e2bb8e61c8bn%40googlegroups.com.