func guadarImagen(c *gin.Context, p *modelo.Prenda) { file, _, err := c.Request.FormFile("foto") if err != nil { c.String(http.StatusSeeOther, "Sin imagen") return } defer file.Close() data, _ := ioutil.ReadAll(file) ruta := "/img/foto" + p.ID.Hex() + ".png" p.Foto = ruta out, err := os.Create("public" + p.Foto) if err != nil { c.String(http.StatusTemporaryRedirect, err.Error()) return } _, err = out.Write(data) if err != nil { c.String(http.StatusTemporaryRedirect, err.Error()) return } defer out.Close() }