Google Code offered in: English - Español - 日本語 - 한국어 - Português - Pусский - 中文(简体) - 中文(繁體)
A Python application can read Blobstore values through a file-like interface, implemented by the BlobReader class. The reader implementation streams data from the Blobstore as needed, so values larger than 1 megabyte can be read, using multiple service calls behind the scenes. This interface is read-only: Blobstore values cannot be modified directly by the application.
BlobReader is provided by the google.appengine.ext.blobstore module.
BlobReader()An application can read data from Blobstore values using an interface
similar to a Python
file object.
This interface can start reading a value at any byte position, and uses multiple service calls and buffering, so an application can access the full size of the value despite the limit on the size of a single service call response.
The BlobReader class can take one of three values as an argument to its constructor:
The object implements the familiar file methods for reading the value. The application cannot modify the Blobstore value; file methods for writing are not implemented.
from google.appengine.ext import blobstore
# blob_key = ...
# Instantiate a BlobReader for a given Blobstore value.
blob_reader = blobstore.BlobReader(blob_key)
# Instantiate a BlobReader for a given Blobstore value, setting the
# buffer size to 1 MB.
blob_reader = blobstore.BlobReader(blob_key, buffer_size=1048576)
# Instantiate a BlobReader for a given Blobstore value, setting the
# initial read position.
blob_reader = blobstore.BlobReader(blob_key, position=4194304)
# Read the entire value into memory. This may take a while depending
# on the size of the value and the size of the read buffer, and is not
# recommended for large values.
value = blob_reader.read()
# Set the read position, then read 100 bytes.
blob_reader.seek(2097152)
data = blob_reader.read(100)
# Read the value, one line (up to and including a '\n' character) at a time.
for line in blob_reader:
# ...
A file-like interface for reading a Blobstore value.
Arguments
BlobInfo,
BlobKey,
or string form of a blob key of the Blobstore value to read. Required.A BlobReader instance has methods and properties similar
to a Python
file object.
Methods that would modify a file (such as write()) are not implemented, and raise an IOError. You can pass a BlobReader object to code expecting a (read-only) file interface (such as the
zipfile
module).
Methods and interfaces include:
pickleclose()
read(size=-1)readline(size=-1)readlines(sizehint=None)seek(offset, whence=SEEK_SET)tell()closed propertyIn addition to the file-like interface, the BlobReader class
provides read-only access to a Blobstore value's
BlobInfo object through the
blob_info property.
BlobInfo object for the instance's Blobstore value.