I am working on a rest endpoint which should get the request body stream and consume it. I tried to get the body of request (Content-Type as text/csv or application/octet-stream) and read from it using buffer.
reader := r.Body.(io.Reader)
writer := bufio.NewWriter(outputFile) // we write to
for {
buffer := make([]byte, 4000)
numBytes, err := reader.Read(buffer)
if err == io.EOF {
break
} else if err != nil {
return
}
if read > 0 {
writer.Write(buffer[0:numBytes])
} else {
break
}
}
writer.Flush();
Above is my golang code. I got nothing from the request.Body. However, if I use multipart/form-data I can get the data from the parts. Does http always require form-data for uploading??