How to read multiple times from same io.Reader

后端 未结 4 1859
一整个雨季
一整个雨季 2020-12-14 14:33

I want to use request.Body(type io.ReadCloser) which is containing a image.

I dont want to use ioutil.ReadAll() as i want to write this bod

4条回答
  •  轮回少年
    2020-12-14 15:04

    When you call ReadAll it's going to empty the buffer, so the second call will always return nothing. What you could do is save the result of ReadAll and reuse that in your functions. For example:

    bytes, _ := ioutil.ReadAll(r);
    log.Println(string(bytes))
    

提交回复
热议问题