Google App Engine

The blobstore package

import "appengine/blobstore"

Introduction

Package blobstore provides a client for App Engine's persistent blob storage service.

Index

func BlobKeyForFile(c appengine.Context, filename string) (appengine.BlobKey, error)
func Create(c appengine.Context, mimeType string) (*Writer, error)
func Delete(c appengine.Context, blobKey appengine.BlobKey) error
func DeleteMulti(c appengine.Context, blobKey []appengine.BlobKey) error
func ParseUpload(req *http.Request) (blobs map[string][]*BlobInfo, other url.Values, err error)
func Send(response http.ResponseWriter, blobKey appengine.BlobKey)
func Stat(c appengine.Context, blobKey appengine.BlobKey) (*BlobInfo, error)
func UploadURL(c appengine.Context, successPath string, opts *UploadURLOptions) (*url.URL, error)
type BlobInfo
type Reader
    func NewReader(c appengine.Context, blobKey appengine.BlobKey) Reader
type UploadURLOptions
type Writer
    func (w *Writer) Close() (closeErr error)
    func (w *Writer) Key() (appengine.BlobKey, error)
    func (w *Writer) Write(p []byte) (n int, err error)

func BlobKeyForFile

func BlobKeyForFile(c appengine.Context, filename string) (appengine.BlobKey, error)

BlobKeyForFile returns a BlobKey for a Google Storage file. The filename should be of the form "/gs/bucket_name/object_name".

func Create

func Create(c appengine.Context, mimeType string) (*Writer, error)

Create begins creating a new blob. The provided mimeType if non-empty is stored in the blob's BlobInfo in datastore, else defaults to application/octet-stream. The returned Writer should be written to, then closed, and then its Key method can be called to retrieve the newly-created blob key if there were no errors.

func Delete

func Delete(c appengine.Context, blobKey appengine.BlobKey) error

Delete deletes a blob.

func DeleteMulti

func DeleteMulti(c appengine.Context, blobKey []appengine.BlobKey) error

DeleteMulti deletes multiple blobs.

func ParseUpload

func ParseUpload(req *http.Request) (blobs map[string][]*BlobInfo, other url.Values, err error)

ParseUpload parses the synthetic POST request that your app gets from App Engine after a user's successful upload of blobs. Given the request, ParseUpload returns a map of the blobs received (keyed by HTML form element name) and other non-blob POST parameters.

func Send

func Send(response http.ResponseWriter, blobKey appengine.BlobKey)

Send sets the headers on response to instruct App Engine to send a blob as the response body. This is more efficient than reading and writing it out manually and isn't subject to normal response size limits.

func Stat

func Stat(c appengine.Context, blobKey appengine.BlobKey) (*BlobInfo, error)

Stat returns the BlobInfo for a provided blobKey. If no blob was found for that key, Stat returns datastore.ErrNoSuchEntity.

func UploadURL

func UploadURL(c appengine.Context, successPath string, opts *UploadURLOptions) (*url.URL, error)

UploadURL creates an upload URL for the form that the user will fill out, passing the application path to load when the POST of the form is completed. These URLs expire and should not be reused. The opts parameter may be nil.

type BlobInfo

type BlobInfo struct {
    BlobKey      appengine.BlobKey
    ContentType  string    `datastore:"content_type"`
    CreationTime time.Time `datastore:"creation"`
    Filename     string    `datastore:"filename"`
    Size         int64     `datastore:"size"`
}

BlobInfo is the blob metadata that is stored in the datastore. Filename may be empty.

type Reader

type Reader interface {
    io.Reader
    io.ReaderAt
    io.Seeker
}

Reader is a blob reader.

func NewReader

func NewReader(c appengine.Context, blobKey appengine.BlobKey) Reader

NewReader returns a reader for a blob. It always succeeds; if the blob does not exist then an error will be reported upon first read.

type UploadURLOptions

type UploadURLOptions struct {
    MaxUploadBytes        int64 // optional
    MaxUploadBytesPerBlob int64 // optional

    // StorageBucket specifies the Google Cloud Storage bucket in which
    // to store the blob.
    // This is required if you use Cloud Storage instead of Blobstore.
    // Your application must have permission to write to the bucket.
    // You may optionally specify a bucket name and path in the format
    // "bucket_name/path", in which case the included path will be the
    // prefix of the uploaded object's name.
    StorageBucket string
}

UploadURLOptions are the options to create an upload URL.

type Writer

type Writer struct {
    // contains filtered or unexported fields
}

Writer is used for writing blobs. Blobs aren't fully written until Close is called, at which point the key can be retrieved by calling the Key method.

func (*Writer) Close

func (w *Writer) Close() (closeErr error)

Close flushes outstanding buffered writes and finalizes the blob. After calling Close the key can be retrieved by calling Key.

func (*Writer) Key

func (w *Writer) Key() (appengine.BlobKey, error)

Key returns the created blob key. It must be called after Close. An error is returned if Close wasn't called or returned an error.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.