io.Copy copies zero bytes

    file, _, err := r.FormFile("profile")
	if err != nil {
		log.Println(err)
		fmt.Fprint(w, err)
	}
	defer file.Close()

	_, _, err = image.Decode(file)
	if err != nil {
		log.Fatal(err)
	}
	buf := bytes.NewBuffer(nil)
	byts, err := io.Copy(buf, file)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(byts, len(buf.Bytes())) // prints 0  0

the io.Copy() copes zero bytes while copying a multipart form file to buffer.
Can anyone help me figuring out what I am doing wrong ?

The image.Decode(file) reads all contents from file so there is nothing left to read for io.Copy(buf, file).

1 Like

yes I figured that out just after I posted the question.
Anyways thanks for the reply.