예제 #1
0
파일: fs.go 프로젝트: jmptrader/tenpu
func (s *Storage) CopyToStorage(attachment *tenpu.Attachment, toBlob tenpu.BlobStorage) (err error) {
	session := s.database.GetOrDialSession().Copy()
	defer session.Close()
	db := session.DB(s.database.DatabaseName)
	reader, err := db.GridFS("fs").OpenId(bson.ObjectIdHex(attachment.Id))
	if err == nil {
		defer reader.Close()
	} else {
		// log.Println("open file error: ", attachment.Id, attachment.Filename)
		return
	}
	err = toBlob.Put(attachment.Filename, attachment.ContentType, reader, attachment)

	return
}
예제 #2
0
파일: handlers.go 프로젝트: jmptrader/tenpu
func resizeAndStore(storage tenpu.BlobStorage, meta tenpu.MetaStorage, thumbnailStorage *Storage, att *tenpu.Attachment, spec *ThumbnailSpec, thumbName string, id string) (thumb *Thumbnail, err error) {

	var buf bytes.Buffer
	storage.Copy(att, &buf)

	if buf.Len() == 0 {
		return
	}
	thumbAtt := &tenpu.Attachment{}

	body, width, height, err := resizeThumbnail(&buf, spec)

	if err != nil {
		return
	}

	err = storage.Put(att.Filename, att.ContentType, body, thumbAtt)
	if err != nil {
		return
	}

	err = meta.Put(thumbAtt)
	if err != nil {
		return
	}

	thumb = &Thumbnail{
		Name:     thumbName,
		ParentId: id,
		BodyId:   thumbAtt.Id,
		Width:    int64(width),
		Height:   int64(height),
	}
	err = thumbnailStorage.Put(thumb)
	return
}