本文整理汇总了Golang中labix/org/v2/mgo.GridFile.Size方法的典型用法代码示例。如果您正苦于以下问题:Golang GridFile.Size方法的具体用法?Golang GridFile.Size怎么用?Golang GridFile.Size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类labix/org/v2/mgo.GridFile
的用法示例。
在下文中一共展示了GridFile.Size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetFileData
func GetFileData(name string) []byte {
var (
result []byte
file *mgo.GridFile
err error
)
file = GetGridFile(name)
result = make([]byte, file.Size())
_, err = file.Read(result)
check(err)
return result
}
示例2: Put
func (s *Storage) Put(filename string, contentType string, body io.Reader, attachment *tenpu.Attachment) (err error) {
var f *mgo.GridFile
s.database.DatabaseDo(func(db *mgo.Database) {
f, err = db.GridFS("fs").Create(filename)
defer f.Close()
if err != nil {
panic(err)
}
if attachment.Id != "" {
f.SetId(bson.ObjectIdHex(attachment.Id))
}
f.SetContentType(contentType)
_, err = io.Copy(f, body)
})
if err == io.ErrUnexpectedEOF {
attId := f.Id().(bson.ObjectId)
s.Delete(attId.Hex())
return
}
if attachment.Id == "" {
attachment.Id = f.Id().(bson.ObjectId).Hex()
attachment.ContentLength = f.Size()
attachment.ContentType = f.ContentType()
attachment.Filename = f.Name()
attachment.MD5 = f.MD5()
if attachment.IsImage() {
s.database.DatabaseDo(func(db *mgo.Database) {
f, err := db.GridFS("fs").OpenId(bson.ObjectIdHex(attachment.Id))
if err == nil {
config, _, err := image.DecodeConfig(f)
f.Close()
if err == nil {
attachment.Width = config.Width
attachment.Height = config.Height
}
}
})
}
}
return
}
示例3: Put
func (s *Storage) Put(filename string, contentType string, body io.Reader, attachment *tenpu.Attachment) (err error) {
var f *mgo.GridFile
s.database.DatabaseDo(func(db *mgo.Database) {
f, err = db.GridFS("fs").Create(filename)
defer f.Close()
if err != nil {
panic(err)
}
f.SetContentType(contentType)
io.Copy(f, body)
})
attachment.Id = f.Id().(bson.ObjectId).Hex()
attachment.ContentLength = f.Size()
attachment.ContentType = f.ContentType()
attachment.Filename = f.Name()
attachment.MD5 = f.MD5()
return
}