Gets the key for a blob.
ReturnsThe BlobKey
instance that identifies this blob.
Gets the entity kind for the BlobInfo
.
The entity kind for BlobInfo
.
Returns the MD5 hash value of the uncompressed blob.
ReturnsThe hash value of the uncompressed blob.
Returns a BlobReader
for this blob.
*args – Arguments to pass to the BlobReader
constructor.
**kwargs – Keyword arguments to pass to the BlobReader
constructor.
A BlobReader
instance.
Defines the set of properties that belong to BlobInfo
.
A set of all of the properties that belong to BlobInfo
.
Returns the size of the uncompressed blob.
ReturnsThe size of the uncompressed blob.
Bases: google.appengine.api.blobstore.blobstore.Error
The CGI parameter does not contain a valid BlobInfo
record.
Bases: object
Key used to identify a blob in Blobstore.
This object wraps a string that gets used internally by the Blobstore API to identify application blobs. The BlobKey corresponds to the entity name of the underlying BlobReference entity.
This class is exposed in the API in both google.appengine.ext.db and google.appengine.ext.blobstore.
Bases: google.appengine.ext.db.Model
Defines a model that records the result of a blob migration.
Fetches the BlobMigrationRecord
for the given blob key.
old_blob_key – The blob key that was used in the previous app.
ReturnsA instance of blobstore.BlobMigrationRecord
or None
.
Looks up the new key for a blob.
Parametersold_blob_key – The original blob key.
ReturnsThe blobstore.BlobKey
of the migrated blob.
Specifies the kind of blob that you are migrating.
ReturnsThe kind of blob that you are migrating
Property compatible with db.Model
classes.
Add references to blobs to domain models using BlobReferenceProperty:
classPicture(db.Model):title=db.StringProperty()image=blobstore.BlobReferenceProperty()thumbnail=blobstore.BlobReferenceProperty()
To find the size of a picture using this model:
picture=Picture.get(picture_key)printpicture.image.size
BlobInfo
objects are lazily loaded, so iterating over models for BlobKeys
is efficient. The following sample code does not need to hit Datastore for each image key:
list_of_untitled_blobs=[]forpictureinPicture.gql("WHERE title=''"):list_of_untitled_blobs.append(picture.image.key())
Bases: google.appengine.api.blobstore.blobstore.Error
The blob does not exist.
Bases: google.appengine.ext.db.Property
Property compatible with db.Model
classes.
Add references to blobs to domain models using BlobReferenceProperty:
classPicture(db.Model):title=db.StringProperty()image=blobstore.BlobReferenceProperty()thumbnail=blobstore.BlobReferenceProperty()
To find the size of a picture using this model:
picture=Picture.get(picture_key)printpicture.image.size
BlobInfo
objects are lazily loaded, so iterating over models for BlobKeys
is efficient. The following sample code does not need to hit Datastore for each image key:
list_of_untitled_blobs=[]forpictureinPicture.gql("WHERE title=''"):list_of_untitled_blobs.append(picture.image.key())
alias of BlobInfo
Returns a model property translated to a datastore value.
Parametersmodel_instance – The model property that you want to translate.
ReturnsThe model property that was translated from datastore.
Returns a datastore value to BlobInfo
.
value – The datastore value that you want to translate.
ReturnsA BlobInfo
that was translated from datastore.
Validates that an assigned value is BlobInfo
.
This method automatically converts from strings and BlobKey
instances.
value – The value that you want to validate.
ReturnsInformation about whether an assigned value is BlobInfo
.
Bases: object
Provides a read-only file-like interface to a blobstore blob.
Returns the BlobInfo
for this file.
A string that contains the BlobInfo
.
Closes the file.
A closed file cannot be read or written to anymore. An operation that requires that the file to be open will raise a ValueError
after the file has been closed. Calling close()
more than once is allowed.
Determines whether a file is closed.
ReturnsTrue
if this file is closed; opened files return False
.
Returns the next line from the file.
ReturnsA string, terminated by \n
. The last line cannot end with \n
. If the end of the file is reached, an empty string will be returned.
StopIteration – If there are no further lines to read.
Reads at most size
bytes from the file.
Fewer bytes are read if the read hits the end of the file before obtaining size
bytes. If the size
argument is negative or omitted, all data is read until the end of the file is reached. The bytes are returned as a string object. An empty string is returned immediately when the end of the file is reached.
Calling read()
without specifying a size
is likely to be dangerous, as it might read excessive amounts of data.
size – Optional. The maximum number of bytes to read. When omitted, read()
returns all remaining data in the file.
The read data, as a string.
Reads one entire line from the file.
A trailing newline character is kept in the string but can be absent when a file ends with an incomplete line. If the size
argument is present and non-negative, it represents a maximum byte count, including the trailing newline and an incomplete line might be returned. An empty string is returned immediately only when the end of the file is reached.
size – Optional. The maximum number of bytes to read.
ReturnsThe read data, as a string.
Reads until the end of the file using readline()
.
A list of lines read is returned.
If the optional sizehint
argument is present, instead of reading up to the end of the file, whole lines totalling approximately sizehint
bytes are read, possibly after rounding up to an internal buffer size.
sizehint – A hint as to the maximum number of bytes to read.
ReturnsA list of strings, each being a single line from the file.
Sets the file’s current position, like stdio’s fseek().
Parametersoffset – The relative offset to seek to.
whence – Optional; defines to what value the offset is relative. This argument defaults to os.SEEK_SET
or 0
to use absolute file positioning; other valid values are os.SEEK_CUR
or 1
to seek relative to the current position and os.SEEK_END
or 2
to seek relative to the end of the file.
Raises an error if you attempt to truncate the file.
Parameterssize – The size that you are attempting to truncate to.
RaisesIOError – If you attempt to truncate a file in BlobReader
.
Raises an error if you attempt to write to the file.
Parametersstr – The string that you are attempting to write.
RaisesIOError – If you attempt to write to a file in BlobReader
.
Raises an error if you attempt to write to the file.
Parameterssequence – The sequence of strings that you are attempting to write.
RaisesIOError – If you attempt to write lines to a file in BlobReader
.
Bases: object
Details information about uploaded files.
This class contains information about blobs stored by an application.
This class is similar to BlobInfo
; however, this method does not make use of a key, and the information is not persisted in the datastore.
content_type: The content type of the uploaded file.
uploaded.
filename: The file name that the user selected from their machine.
size: The size of the uncompressed file.
md5_hash: The MD5 hash value of the uploaded file.
gs_object_name: The name of the file that was written to Google Cloud Storage, or None
if the file was not uploaded to Google Cloud Storage.
All properties are read-only. Attempting to assign a value to a property will raise an AttributeError
.
Returns the content type of the uploaded file.
ReturnsThe content type of the file.
Returns the creation date or upload time of the file.
ReturnsThe creation date or upload time of the file.
Returns the file name that the user selected.
ReturnsThe file name that the user selected.
Returns the name of the file that was written to Cloud Storage.
ReturnsThe name of the file that was written to Cloud Storage.
Returns the MD5 hash of the uploaded file.
ReturnsThe hash value for the uploaded file.
Returns the size of the uncompressed file.
ReturnsThe size of the uncompressed file.
Bases: google.appengine.api.blobstore.blobstore.Error
The CGI parameter does not contain a valid FileInfo
record.
Bases: google.appengine.api.blobstore.blobstore.Error
The indexes could not be accessed.
The specified indexes were out of range or in the wrong order.
Bases: google.appengine.api.blobstore.blobstore.Error
The operation did not complete; review the permissions required.
Bases: exceptions.Exception
Base blobstore error type.
Bases: google.appengine.api.blobstore.blobstore.Error
An internal error occured.
Creates an RPC object to use with the Blobstore API.
Parametersdeadline – Optional deadline in seconds for the operation; the default value is a system-specific deadline, typically 5 seconds.
callback – Optional callable to invoke on completion.
An apiproxy_stub_map.UserRPC
object that is specialized for this service.
Creates the upload URL for a POST form.
Parameterssuccess_path – Path within application to call when a POST
call is successful and the upload is complete.
max_bytes_per_blob – The maximum size in bytes that any one blob in the upload can be, or None
for no maximum size.
max_bytes_total – The maximum size in bytes that the aggregate sizes of all of the blobs in the upload can be, or None
for no maximum size.
rpc – Optional UserRPC object.
gs_bucket_name – The Google Cloud Storage bucket name to which the blobs should be uploaded. The application’s service account must have the correct permissions to write to this bucket. The bucket name can be of the format bucket/path/
, in which case the included path will be prepended to the uploaded object name.
The upload URL.
RaisesTypeError – If max_bytes_per_blob
or max_bytes_total
are not integral types.
ValueError – If max_bytes_per_blob
or max_bytes_total
are not positive values.
Asynchronously creates the upload URL for a POST form.
Parameterssuccess_path – The path within the application to call when a POST
call is successful and the upload is complete.
max_bytes_per_blob – The maximum size in bytes that any one blob in the upload can be, or None
for no maximum size.
max_bytes_total – The maximum size in bytes that the aggregate sizes of all of the blobs in the upload can be, or None
for no maximum size.
rpc – Optional UserRPC object.
gs_bucket_name – The Google Cloud Storage bucket name to which the blobs should be uploaded. The application’s service account must have the correct permissions to write to this bucket. The bucket name can be of the format bucket/path/
, in which case the included path will be prepended to the uploaded object name.
A UserRPC whose result will be the upload URL.
RaisesTypeError – If max_bytes_per_blob
or max_bytes_total
are not integral types.
ValueError – If max_bytes_per_blob
or max_bytes_total
are not positive values.
Deletes a blob from Blobstore.
Parametersblob_keys – A single BlobKey
instance or a list of blob keys. A blob key can be either a string or an instance of BlobKey
.
rpc – Optional UserRPC object.
None.
Asynchronously deletes a blob from Blobstore.
Parametersblob_keys – A single BlobKey
instance or a list of blob keys. A blob key can be either a string or an instance of BlobKey
.
rpc – Optional UserRPC object.
A UserRPC, whose result will be None
.
Fetches data for a blob.
Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE
in length. Attempting to fetch a fragment that extends beyond the boundaries of the blob will return the amount of data from start_index
until the end of the blob, which will be a smaller size than requested. Requesting a fragment that is entirely outside the boundaries of the blob will return an empty string. Attempting to fetch a negative index will raise an exception.
blob – A BlobInfo
, BlobKey
, string, or Unicode representation of the BlobKey
of the blob from which you want to fetch data.
start_index – The start index of blob data to fetch. This value must not be negative.
end_index – The end index (inclusive) of the blob data to fetch. This value must be greater than or equal to start_index
.
rpc – Optional UserRPC object.
A string that contains partial data of a blob. If the indexes are legal but outside of the boundaries of the blob, an empty string is returned.
RaisesTypeError – If start_index
or end_index
are not indexes, or if blob
is not a string, BlobKey
or BlobInfo
.
DataIndexOutOfRangeError – If start_index
is set to a value that is less than 0 or end_index
is less than start_index
.
BlobFetchSizeTooLargeError – If the requested blob fragment is larger than MAX_BLOB_FETCH_SIZE
.
BlobNotFoundError – If the blob does not exist.
Asynchronously fetches data for a blob.
Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE
in length. Attempting to fetch a fragment that extends beyond the boundaries of the blob will return the amount of data from start_index
until the end of the blob, which will be a smaller size than requested. Requesting a fragment that is entirely outside the boundaries of the blob will return an empty string. Attempting to fetch a negative index will raise an exception.
blob – A BlobInfo
, BlobKey
, string, or Unicode representation of the BlobKey
of the blob from which you want to fetch data.
start_index – The start index of blob data to fetch. This value must not be negative.
end_index – The end index (inclusive) of the blob data to fetch. This value must be greater than or equal to start_index
.
rpc – Optional UserRPC object.
A UserRPC whose result will be a string as returned by fetch_data()
.
TypeError – If start_index
or end_index
are not indexes, or if blob
is not a string, BlobKey
or BlobInfo
.
DataIndexOutOfRangeError – If start_index
is set to a value that is less than 0 or end_index
is less than start_index
when calling rpc.get_result()
.
BlobFetchSizeTooLargeError – If the requested blob fragment is larger than MAX_BLOB_FETCH_SIZE
when calling rpc.get_result()
.
BlobNotFoundError – If the blob does not exist when calling rpc.get_result()
.
Creates an encoded key for a Google Cloud Storage file.
It is safe to persist this key for future use.
Parametersfilename – The file name of the Google Cloud Storage object for which you want to create the key.
rpc – Optional UserRPC object.
An encrypted BlobKey
string.
Asynchronously creates an encoded key for a Google Cloud Storage file.
It is safe to persist this key for future use.
Parametersfilename – The file name of the Google Cloud Storage object for which you want to create the key.
rpc – Optional UserRPC object.
A UserRPC whose result will be a string as returned by create_gs_key()
.
TypeError – If filename
is not a string.
ValueError – If filename
is not in the format /gs/bucket_name/object_name
.
Gets a BlobInfo
record from blobstore.
Does the same as BlobInfo.get
.
blob_key – The BlobKey
of the record you want to retrieve.
A BlobInfo
instance that is associated with the provided key or a list of BlobInfo
instances if a list of keys was provided. Keys that are not found in Blobstore return None
.
Parses a BlobInfo
record from file upload field_storage
.
field_storage – cgi.FieldStorage
that represents an uploaded blob.
A BlobInfo
record as parsed from the field_storage
instance. This method will return None
if field_storage
was not defined.
BlobInfoParseError – If the provided field_storage
does not contain enough information to construct a BlobInfo
object.
Parses a FileInfo
record from file upload field_storage
.
field_storage – cgi.FieldStorage
that represents the uploaded file.
FileInfo
record as parsed from the field_storage
instance. This method will return None
if field_storage
was not specified.
FileInfoParseError – If field_storage
does not contain enough information to construct a FileInfo
object.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-04-04 UTC.