i have a question,
How can i send a file over an http POST request directly to the receiver?
I mean, without saving it first to the memory, because say the file is large (>1Gb), this will give a memory error. I have used this pattern:
file, _ := os.Open(fileName);
req, err := http.NewRequest("POST", "http://"+serverAddress + fileName, file);
if err != nil {
fmt.Println("Error creating the request: " + err.Error());
}
client := &http.Client{}
_, err = client.Do(req)
if err != nil {
fmt.Println("Error sending the request: " + err.Error());
}
but this gives this error:
Error unmarshaling body: invalid character […]
Also passing an io.Reader gives the same error.
I want to send the file directly to the receiver without processing it.
Thank You