import "code.google.com/p/appengine-go/appengine/blobstore"
blobstore包提供持久大对象的存储服务。
func BlobKeyForFile(c appengine.Context, filename string) (appengine.BlobKey, error)
返回一个google存储文件的BlobKey,文件名格式为: "/gs/bucket_name/object_name"。
func Delete(c appengine.Context, blobKey appengine.BlobKey) error
删除一个大对象。
func DeleteMulti(c appengine.Context, blobKey []appengine.BlobKey) error
Delete的批处理版本。
type BlobInfo struct { BlobKey appengine.BlobKey ContentType string `datastore:"content_type"` CreationTime time.Time `datastore:"creation"` Filename string `datastore:"filename"` Size int64 `datastore:"size"` MD5 string `datastore:"md5_hash"` // ObjectName是blob的google云存储名 ObjectName string `datastore:"gs_object_name"` }
BlobInfo是大对象的元数据,该信息会保存在datastore里,文件名可以为空。
func Stat(c appengine.Context, blobKey appengine.BlobKey) (*BlobInfo, error)
返回blobKey对应的大对象的元数据信息,如果没有对应的大对象,会返回datastore.ErrNoSuchEntity。
type Reader interface { io.Reader io.ReaderAt io.Seeker }
Reader是大对象的读接口。
func NewReader(c appengine.Context, blobKey appengine.BlobKey) Reader
返回blobKey对应的大对象的读接口。如果不存在对应的大对象,函数返回的接口第一次调用Read时报错。
type Writer struct {
// 内含隐藏字段
}
Writer用于写入大对象。只有在调用Close时才保证全部写入,之后可以获取键。
func Create(c appengine.Context, mimeType string) (*Writer, error)
函数创建一个大对象的写接口,mimeType如果非空会记录在大对象的元数据里保存到datastore里,否则会默认为application/octet-stream。返回的Writer指针应该在写入数据后关闭,如没有发生错误即可获取该大对象的键。
func (w *Writer) Key() (appengine.BlobKey, error)
返回创建的blobstore的键,必须在关闭后才能调用,未关闭前调用会导致错误。
func (w *Writer) Write(p []byte) (n int, err error)
func (w *Writer) Close() (closeErr error)
清空缓存,结束blob的写入。关闭后才能获取blob键。
type UploadURLOptions struct { MaxUploadBytes int64 // 可选的 MaxUploadBytesPerBlob int64 // 可选的 // StorageBucket指定了google云存储中保存该大对象的bucket。 // 如果你使用云存储代替blobstore的话,该参数就是必要的。 // 你的app必须有写入该bucket的权限。 // 你可以随意地用"bucket_name/path"格式指定bucket名和路径, // 在这种情况下,path将会成为上传对象的名字的前缀。 StorageBucket string }
UploadURLOptions是创建上传URL的选项。
func UploadURL(c appengine.Context, successPath string, opts *UploadURLOptions) (*url.URL, error)
创建一个上传URL,用户填写表单后上传到这个URL,在上传成功后会重定向到successPath。该URL会过期,也不可以重用。opts参数可以是nil。
func ParseUpload(req *http.Request) (blobs map[string][]*BlobInfo, other url.Values, err error)
在用户成功上传大对象后,函数解析你的app从App Engine接手的POST请求,返回一个接收到的大对象的字典(键为HTML表单的元素名),以及其它非大对象POST参数。
func Send(response http.ResponseWriter, blobKey appengine.BlobKey)
函数设置response的header并将blobKey对应的大对象的内容作为response的body。本函数比手工读取大对象和写入response要更有效率,也没有一般response大小的限制。