google.appengine.api.blobstore.blobstore_stub.BlobstoreServiceStub

Datastore backed Blobstore service stub.

Inherits From: APIProxyStub, expected_type

This stub stores manages upload sessions in the Datastore and must be provided with a blob_storage object to know where the actual blob records can be found after having been uploaded.

This stub does not handle the actual creation of blobs, neither the BlobInfo in the Datastore nor creation of blob data in the blob_storage. It does, however, assume that another part of the system has created these and uses these objects for deletion.

An upload session is created when the CreateUploadURL request is handled and put in the Datastore under the BlobUploadSession kind. There is no analog for this kind on a production server. Other than creation, this stub not work with session objects. The URLs created by this service stub are:

http://://

This is very similar to what the URL is on a production server. The session info is the string encoded version of the session entity

blob_storage BlobStorage class instance used for blob storage.
time_function Used for dependency injection in tests.
service_name Service name expected for all calls.
uploader_path Path to upload handler pointed to by URLs generated by this service stub.
request_data A apiproxy_stub.RequestData instance used to look up state associated with the request that generated an API call.
storage_dir Directory for blobstore file storage if clients sets no_storage to true.
app_id App ID for blobstore file storage.

storage Access BlobStorage used by service stub.

Methods

CreateBlob

View source

Create new blob and put in storage and Datastore.

This is useful in testing where you have access to the stub.

Args
blob_key String blob-key of new blob.
content Content of new blob as a string.

Returns
New Datastore entity without blob meta-data fields.

CreateEncodedGoogleStorageKey

View source

Create an encoded blob key that represents a Google Storage file.

For now we'll just base64 encode the Google Storage filename, APIs that accept encoded blob keys will need to be able to support Google Storage files or blobstore files based on decoding this key.

Any stub that creates GS files should use this function to convert a gs filename to a blobkey. The created blobkey should be used both as its _GS_FILE_INFO entity's key name and as the storage key to store its content in blobstore. This ensures the GS files created can be operated by other APIs.

Note this encoding is easily reversible and is not encryption.

Args
filename gs filename of form 'bucket/filename'

Returns
blobkey string of encoded filename.

CreateRPC

View source

Creates RPC object instance.

Returns
An instance of RPC.

DeleteBlob

View source

Delete a blob.

Args
blobkey blobkey in str.
storage blobstore storage stub.

MakeSyncCall

View source

The main RPC entry point.

Args
service Must be name as provided to service_name of constructor.
call A string representing the rpc to make. Must be part of the underlying services methods and impemented by _Dynamic_<call>.
request A protocol buffer of the type corresponding to call.
response A protocol buffer of the type corresponding to call.
request_id A unique string identifying the request associated with the API call.

SetError

View source

Set an error condition that may be raised when calls made to stub.

If a method is specified, the error will only apply to that call. The error rate is applied to the method specified or all calls if method is not set.

Args
error An instance of apiproxy_errors.Error or None for no error.
method A string representing the method that the error will affect.
error_rate a number from [0, 1] that sets the chance of the error, defaults to 1.

ToDatastoreBlobKey

View source

Given a string blobkey, return its db.Key.

GS_BLOBKEY_PREFIX 'encoded_gs_file:'
THREADSAFE False