Create a gist now

Instantly share code, notes, and snippets.

Solution for question "Reading image from HTTP request's body in Go" at SO
package main
import (
var client = http.Client{}
func cutterHandler(res http.ResponseWriter, req *http.Request) {
reqImg, err := client.Get("")
if err != nil {
fmt.Fprintf(res, "Error %d", err)
buffer := make([]byte, reqImg.ContentLength)
io.ReadFull(reqImg.Body, buffer)
res.Header().Set("Content-Length", fmt.Sprint(reqImg.ContentLength))
res.Header().Set("Content-Type", reqImg.Header.Get("Content-Type"))
func main() {
http.HandleFunc("/cut", cutterHandler)
http.ListenAndServe(":8080", nil) /* TODO Configurable */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment