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
An application can read data from Blobstore values using an interface
similar to a Python
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: # ...
- class BlobReader(blob_key, buffer_size=131072, position=0)
A file-like interface for reading a Blobstore value.
BlobKey, or string form of a blob key of the Blobstore value to read. Required.
- The size of the input buffer, as a number of bytes. The default is 128 kilobytes (131,072 bytes). The buffer size cannot exceed 1 megabyte (1,048,576 bytes).
- The byte position of the first byte to read. The default is to start reading at the beginning of the value (byte position 0).
BlobReader instance has methods and properties similar
to a Python
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
Methods and interfaces include:
- iterator and iterable interfaces
- interfaces to support serialization of BlobReader state via
In addition to the file-like interface, the
provides read-only access to a Blobstore value's
BlobInfo object through the
BlobInfoobject for the instance's Blobstore value.