English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# The BlobInfo Class

Every Blobstore value has a corresponding entity in the datastore containing information about the blob, such as its filename and size. The BlobInfo class provides a `db.Model`-like interface to this read-only entity. You can retrieve BlobInfo objects using a Blobstore key.

`BlobInfo` is provided by the `google.appengine.ext.blobstore` module.

- Introduction
- Class methods:
  - `BlobInfo.all()`
  - `BlobInfo.get()`
  - `BlobInfo.gql()`
  - `BlobInfo.kind()`
  - `BlobInfo.properties()`
- Instance methods:
  - `delete()`
  - `key()`
  - `open()`
- Instance properties:
  - `content_type`
  - `creation`
  - `filename`
  - `size`

## Introduction

Every Blobstore value has a corresponding BlobInfo entity in the datastore that contains information about the blob, such as its filename and size. The Blobstore creates this entity when the blob is uploaded. Unlike other datastore entities, BlobInfo entities are read-only, and cannot be modified by the application.

An application can query for BlobInfo entities by their properties, and can fetch an entity using the Blobstore key. Note that a query over multiple properties on a BlobInfo entity may require a custom index, just as with other entities.

When a blob is uploaded, the Blobstore passes the metadata to the upload handler in the headers of the MIME part for the file. The upload handler can parse this information into a BlobInfo object without calling the datastore using the `parse_blob_info()` function. If you're using the webapp application framework, you can use the `BlobstoreUploadHandler` for more convenient parsing of this information.

## Class Methods

The BlobInfo class has the following class methods:

BlobInfo.all()

  Returns a `Query` object that represents all BlobInfo entities for the application. Methods on the Query object can apply filters and sort orders to the query before it is executed. See `Query` for more information.

BlobInfo.get(blob_keys)

  Gets the BlobInfo object (or objects) for the given `BlobKey` objects.

  Arguments

  blob_keys
    A `BlobKey` value, or a list of `BlobKey` values.

  If given a single `BlobKey`, returns a `BlobInfo` object, or `None` if there is no Blobstore value for that key. If given a list of `BlobKey` values, returns a list with one value for each given key, each of which is either a `BlobKey` or `None`.

BlobInfo.gql(query_string, *args, **kwds)

  Performs a GQL query over `BlobInfo` entities.

  Arguments

  query_string
    The part of the GQL query following `SELECT * FROM model` (which is implied by using this class method).
  *args
    Positional parameter bindings, similar to the `GqlQuery` constructor.
  **kwds
    Keyword parameter bindings, similar to the `GqlQuery` constructor.

  The return value is a `GqlQuery` object, which can be used to access the results.

BlobInfo.kind()
  Returns the kind name used for `BlobInfo` entities.
BlobInfo.properties()
  Returns a dictionary of all of the properties defined for `BlobInfo` entities.

## Instance Methods

A BlobInfo instance has the following methods:

delete()

  Deletes the Blobstore value represented by this BlobInfo object, and also deletes the corresponding BlobInfo entity from the datastore.

  Deleting a Blobstore value occurs separately from datastore transactions. If you call this method during a datastore transaction, it takes effect immediately, regardless of whether the transaction commits successfully or is retried.

key()

  Returns the `BlobKey` of the Blobstore value described by this `BlobInfo`.

open()

  Returns a `BlobReader` for this blob.

## Instance Properties

A `BlobInfo` instance has several properties. These properties are present on the `BlobInfo` Datastore entity, and can be the subject of queries via the `BlobInfo.all()` and `BlobInfo.gql`() class methods.

content_type
  The MIME content type of the Blobstore value, as provided by the client that uploaded the value. A string.
creation
  The date and time the Blobstore value was created. A `datetime` value.
filename
  The filename of the Blobstore value, as provided by the client that uploaded the value. A string.
size
  The size of the Blobstore value, as a number of bytes. An integer.