예제 #1
0
파일: picture.go 프로젝트: xausee/symbol
func (this Picture) PostUploadForCheck() revel.Result {
	// 彩色版本照片
	fpCO, err := this.saveFile("COPictureFile")
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect(Picture.UploadForCheck)
	}

	t := time.Now()
	id := strconv.Itoa(t.Year()) + strconv.Itoa((int)(t.Month())) +
		strconv.Itoa(t.Day()) + strconv.Itoa(t.Hour()) +
		strconv.Itoa(t.Minute()) + strconv.Itoa(t.Second())
	fpOnQiNiuCO := "PCO" + id + path.Ext(fpCO)

	// 上传图片到七牛云储存(彩色版本)
	err = models.UploadToQiniu(fpCO, fpOnQiNiuCO, models.QiNiuBucketPre)
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect(Picture.UploadForCheck)
	}

	picture := models.Picture{
		ID:             id,
		Name:           this.Params.Form.Get("Name"),
		Contributor:    this.Params.Form.Get("Contributor"),
		University:     this.Params.Form.Get("University"),
		Classification: this.Params.Form.Get("Classification"),
		Discription:    this.Params.Form.Get("Discription"),
		PathOfColor:    models.QiNiuSpacePre + fpOnQiNiuCO}

	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	err = manager.AddPrePicture(picture)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect(Picture.UploadForCheck)
	}

	// 删除临时图片文件
	err = os.Remove(fpCO)
	if err != nil {
		log.Println("删除临时图片文件失败:", err)
	}

	this.Flash.Success("图片上传成功!")
	return this.Redirect(Picture.UploadForCheck)
}
예제 #2
0
파일: picture.go 프로젝트: xausee/symbol
func (this Picture) PostEdit(id string) revel.Result {
	// 黑白版本照片
	fpBW, err := this.saveFile("BWPictureFile")
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	// 彩色版本照片
	fpCO, err := this.saveFile("COPictureFile")
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	t := time.Now()
	nid := strconv.Itoa(t.Year()) + strconv.Itoa((int)(t.Month())) +
		strconv.Itoa(t.Day()) + strconv.Itoa(t.Hour()) +
		strconv.Itoa(t.Minute()) + strconv.Itoa(t.Second())
	fpOnQiNiuBW := "PBW" + nid + path.Ext(fpBW)
	fpOnQiNiuCO := "PCO" + nid + path.Ext(fpCO)

	// 上传图片到七牛云储存(黑白版本)
	err = models.UploadToQiniu(fpBW, fpOnQiNiuBW, models.QiNiuBucket)
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	// 删除临时图片文件
	err = os.Remove(fpBW)
	if err != nil {
		log.Println("删除临时图片文件失败:", err)
	}

	// 上传图片到七牛云储存(彩色版本)
	err = models.UploadToQiniu(fpCO, fpOnQiNiuCO, models.QiNiuBucket)
	if err != nil {
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	err = os.Remove(fpCO)
	if err != nil {
		log.Println("删除临时图片文件失败:", err)
	}

	picture := models.Picture{
		ID:             id,
		Name:           this.Params.Form.Get("Name"),
		University:     this.Params.Form.Get("University"),
		Classification: this.Params.Form.Get("Classification"),
		Discription:    this.Params.Form.Get("Discription"),
		PathOfBW:       models.QiNiuSpace + fpOnQiNiuBW,
		PathOfColor:    models.QiNiuSpace + fpOnQiNiuCO}

	manager, err := models.NewDBManager()
	if err != nil {
		log.Println("链接数据库失败")
	}
	defer manager.Close()

	err = manager.UpdatePicture(&picture)
	if err != nil {
		log.Println(err)
		this.Response.Status = 500
		this.Flash.Error(err.Error())
		return this.Redirect("Edit?id=%s", id)
	}

	this.Flash.Success("图片更新成功!")
	return this.Redirect("Show?id=%s", id)
}