I could be misleading you here, but my immediate thought is that whether you
can stream the body/payload depends on what form you're receiving the query
result in? if it's an io.Reader then it looks like you could use it
directly. otherwise
i'm not sure what you could do to the HTTP client to change that (since the
query result would have already materialized).

On Tue, Mar 7, 2023 at 5:36 AM Amnon <amno...@gmail.com> wrote:

> 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
> <https://groups.google.com/d/msgid/golang-nuts/d9e4e00f-2251-453c-88f2-5e2bb8e61c8bn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
*Curried programmer*
*Homepage*: http://yawboakye.com
I'm tweeting <https://twitter.com/@22bytes> when I'm not coding
<https://github.com/yawboakye> when I'm not holding my niece.

-- 
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/CAPJoGXsHvNT%2BsMxVs5w9Z%3DSYdyCOrDBYEHh9s6tWui_gVU%3Do4g%40mail.gmail.com.

Reply via email to