Example #1
0
func (self *Backend) FileReader(id string) (reader io.ReadCloser, filename, contentType string, err error) {
	file, err := self.GridFS.OpenId(bson.ObjectIdHex(id))
	if err == mgo.ErrNotFound {
		return nil, "", "", media.ErrNotFound(id)
	} else if err != nil {
		return nil, "", "", err
	}
	filename = id[strings.IndexRune(id, '/')+1:]
	return file, filename, file.ContentType(), nil
}
Example #2
0
func (self *Backend) LoadBlob(id string) (*media.Blob, error) {
	var doc BlobDoc
	err := self.Blobs.DocumentWithID(bson.ObjectIdHex(id), &doc)
	if err == mgo.ErrNotFound {
		return nil, media.ErrNotFound(id)
	} else if err != nil {
		return nil, err
	}
	return doc.Blob.Init(), nil
}
Example #3
0
func (self *Backend) LoadImage(id string) (*media.Image, error) {
	var doc ImageDoc
	err := self.Images.DocumentWithID(bson.ObjectIdHex(id), &doc)
	if err == mgo.ErrNotFound {
		return nil, media.ErrNotFound(id)
	} else if err != nil {
		return nil, err
	}
	return doc.Image.Init(), nil
}