Ok, cool, thanks — that was what I asked in my OP :)
> Is this possible at all with the stdlib http.Client? Perhaps with an io.Pipe
> as the request body?
/J
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and st
On Wed, Mar 22, 2023 at 8:32 PM 'Christian Stewart' via golang-nuts <
golang-nuts@googlegroups.com> wrote:
> you can achieve this using an io.Pipe. The io.Pipe function returns a
> connected pair of *PipeReader and *PipeWriter, where writes to the
> *PipeWriter are directly read from the *PipeRead
you can achieve this using an io.Pipe. The io.Pipe function returns a
connected pair of *PipeReader and *PipeWriter, where writes to the
*PipeWriter are directly read from the *PipeReader. The Write call on the
*PipeWriter will block until the data is read from the *PipeReader.
pr, pw := io.Pipe()
The issue here, isn’t that I am uploading a big file — that’s easy.
As I said in my initial 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 databa
You are right, I overlooked the "bigfile" name clearly suggesting it's
about the big content being uploaded. My bad.
Anyway, what's important for the OP is that net/http is well-designed and
will let you do what you need in this case.
cheers,
-W.
wtorek, 7 marca 2023 o 23:07:15 UTC+1 Christia
PS. My choice of http.Request with client.Do was misleading, http.Post can
be used as well:
func uploadStdin(url string) error {
resp, err := http.Post(url, "text/plain", os.Stdin)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
No... The previous example streams the file as the post request. The only
difference in your example is that you're using stdin.
It's not that complicated, files also implement io.reader.
On Tue, Mar 7, 2023, 1:41 PM Wojciech Kaczmarek wrote:
> Hello,
>
> I think this code example rather stream
Hello,
I think this code example rather streams back the response the server sent
from its POST handler
and it is not exactly what the OP requested ;) (not to mention that the
typical result of a POST is
an immediate redirect, possibly without body at all).
I believe what Jim needs is construct
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 chang
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.B
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 <
golang-nuts@g
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 generat
12 matches
Mail list logo