Exemplo n.º 1
0
func Upload(c *middleware.Context) {
	c.Req.ParseMultipartForm(32 << 20)
	file, _, err := c.Req.FormFile("uploadfile")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()

	name := uuid.NewV4().String()

	//.fmt.Fprintf(w, "%v", handler.Header)
	err = os.MkdirAll("data/uploads/"+makePaths(name), 0777)
	if err != nil {
		return
	}
	f, err := os.OpenFile("data/uploads/"+makePaths(name)+"/"+name, os.O_WRONLY|os.O_CREATE, 0777)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f.Close()
	io.Copy(f, file)
	c.JSON(200, makePaths(name))
}
Exemplo n.º 2
0
func screen(siteId int64) (string, error) {
	site, e := models.GetSite(siteId)
	if e != nil {
		return "", e
	}

	rdr, e := shot.Shot(site.Domain)
	if e != nil {
		return "", e
	}

	name := uuid.NewV4().String()

	//.fmt.Fprintf(w, "%v", handler.Header)
	e = os.MkdirAll("data/uploads/"+makePaths(name), 0777)
	if e != nil {
		return "", e
	}
	f, e := os.OpenFile("data/uploads/"+makePaths(name)+"/"+name, os.O_WRONLY|os.O_CREATE, 0777)
	if e != nil {
		return "", e
	}
	defer f.Close()
	_, e = io.Copy(f, rdr)
	if e != nil {
		return "", e
	}

	fp := filepath.Join("/", makePaths(name), "/", name)
	site.PreviewUrl = fp
	e = models.SaveSite(site)
	if e != nil {
		return "", e
	}
	return fp, nil
}