Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 23, 2022 17:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
func descargarArchivoDeInternet(url string) (string, error) {
respuesta, err := http.Get(url)
if err != nil {
return "", err
}
defer respuesta.Body.Close()
nombreArchivoSalida := fmt.Sprintf("%s.%s", xid.New().String(), extensionImagenSegunContentType(respuesta.Header.Get("Content-Type")))
archivoSalida, err := os.Create(nombreArchivoSalida)
if err != nil {
return "", err
}
defer archivoSalida.Close()
_, err = io.Copy(archivoSalida, respuesta.Body)
return nombreArchivoSalida, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment