Skip to content

Instantly share code, notes, and snippets.

@darmawan01
Created July 12, 2021 06:00
Show Gist options
  • Save darmawan01/0c2beaa2f763fa45137c4d22c592bf27 to your computer and use it in GitHub Desktop.
Save darmawan01/0c2beaa2f763fa45137c4d22c592bf27 to your computer and use it in GitHub Desktop.
Serve buffer bytes to file for http
f, err := ioutil.TempFile("", uuid+".*.pdf")
	if err != nil {
		log.Print("ioutil.TempFile(): ", err)
		return
	}

	// Write the body to file
	if _, err = io.Copy(f, buffReader); err != nil {
		log.Print("io.Copy(): ", err)
		return
	}

	http.ServeFile(w, r, f.Name())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment