本文整理匯總了Python中google.appengine.ext.blobstore.create_gs_key方法的典型用法代碼示例。如果您正苦於以下問題:Python blobstore.create_gs_key方法的具體用法?Python blobstore.create_gs_key怎麽用?Python blobstore.create_gs_key使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.ext.blobstore
的用法示例。
在下文中一共展示了blobstore.create_gs_key方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def get(self):
# Get the default Cloud Storage Bucket name and create a file name for
# the object in Cloud Storage.
bucket = app_identity.get_default_gcs_bucket_name()
# Cloud Storage file names are in the format /bucket/object.
filename = '/{}/blobstore_serving_demo'.format(bucket)
# Create a file in Google Cloud Storage and write something to it.
with cloudstorage.open(filename, 'w') as filehandle:
filehandle.write('abcde\n')
# In order to read the contents of the file using the Blobstore API,
# you must create a blob_key from the Cloud Storage file name.
# Blobstore expects the filename to be in the format of:
# /gs/bucket/object
blobstore_filename = '/gs{}'.format(filename)
blob_key = blobstore.create_gs_key(blobstore_filename)
# BlobstoreDownloadHandler serves the file from Google Cloud Storage to
# your computer using blob_key.
self.send_blob(blob_key)
示例2: process_export
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def process_export():
bucket = int(flask.request.values['bucket'])
filename = '/ilps-search-log.appspot.com/search_log.%d.gz' % bucket
with gcs.open(filename, 'w' , 'text/plain', {'content-encoding': 'gzip'}) as f:
bucket_size = int(flask.request.values['bucket_size'])
offset = bucket * bucket_size
with gzip.GzipFile('', fileobj=f, mode='wb') as gz:
ndb.get_context().clear_cache()
for s in Session.query(Session.shared == True).iter(batch_size=10,
offset=offset, limit=bucket_size):
ndb.get_context().clear_cache()
gc.collect()
s.user_id = ''
print >>gz, json.dumps(s.to_dict(), default=util.default,
ensure_ascii=False).encode('utf-8')
response = 'Written: %s' % str(blobstore.create_gs_key('/gs' + filename))
app.logger.info(response)
return response, 200
示例3: run
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def run(self, mr_type, encoded_key, output):
logging.debug("output is %s" % str(output))
key = db.Key(encoded=encoded_key)
m = FileMetadata.get(key)
blobstore_filename = "/gs" + output[0]
blobstore_gs_key = blobstore.create_gs_key(blobstore_filename)
url_path = "/blobstore/" + blobstore_gs_key
if mr_type == "WordCount":
m.wordcount_link = url_path
elif mr_type == "Index":
m.index_link = url_path
elif mr_type == "Phrases":
m.phrases_link = url_path
m.put()
示例4: get_blob_key
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def get_blob_key(filename):
return blobstore.create_gs_key('/gs' + _path(filename))
示例5: get_blobkey
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def get_blobkey(self, gs_filename):
return blobstore.create_gs_key(gs_filename)
示例6: get
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def get(self):
# Get the default Cloud Storage Bucket name and create a file name for
# the object in Cloud Storage.
bucket = app_identity.get_default_gcs_bucket_name()
# Cloud Storage file names are in the format /bucket/object.
filename = '/{}/blobreader_demo'.format(bucket)
# Create a file in Google Cloud Storage and write something to it.
with cloudstorage.open(filename, 'w') as filehandle:
filehandle.write('abcde\n')
# In order to read the contents of the file using the Blobstore API,
# you must create a blob_key from the Cloud Storage file name.
# Blobstore expects the filename to be in the format of:
# /gs/bucket/object
blobstore_filename = '/gs{}'.format(filename)
blob_key = blobstore.create_gs_key(blobstore_filename)
# [START gae_blobstore_reader]
# Instantiate a BlobReader for a given Blobstore blob_key.
blob_reader = blobstore.BlobReader(blob_key)
# Instantiate a BlobReader for a given Blobstore blob_key, setting the
# buffer size to 1 MB.
blob_reader = blobstore.BlobReader(blob_key, buffer_size=1048576)
# Instantiate a BlobReader for a given Blobstore blob_key, setting the
# initial read position.
blob_reader = blobstore.BlobReader(blob_key, position=0)
# 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.
blob_reader_data = blob_reader.read()
# Write the contents to the response.
self.response.headers['Content-Type'] = 'text/plain'
self.response.write(blob_reader_data)
# Set the read position back to 0, then read and write 3 bytes.
blob_reader.seek(0)
blob_reader_data = blob_reader.read(3)
self.response.write(blob_reader_data)
self.response.write('\n')
# Set the read position back to 0, then read and write one line (up to
# and including a '\n' character) at a time.
blob_reader.seek(0)
for line in blob_reader:
self.response.write(line)
# [END gae_blobstore_reader]
# Delete the file from Google Cloud Storage using the blob_key.
blobstore.delete(blob_key)
示例7: delete
# 需要導入模塊: from google.appengine.ext import blobstore [as 別名]
# 或者: from google.appengine.ext.blobstore import create_gs_key [as 別名]
def delete(*filenames):
"""Permanently delete files.
Delete on non-finalized/non-existent files is a no-op.
Args:
filenames: finalized file names as strings. filename should has format
"/gs/bucket/filename" or "/blobstore/blobkey".
Raises:
InvalidFileNameError: Raised when any filename is not of valid format or
not a finalized name.
IOError: Raised if any problem occurs contacting the backend system.
"""
from google.appengine.api.files import blobstore as files_blobstore
from google.appengine.api.files import gs
from google.appengine.ext import blobstore
blobkeys = []
for filename in filenames:
if not isinstance(filename, basestring):
raise InvalidArgumentError('Filename should be a string, but is %s(%r)' %
(filename.__class__.__name__, filename))
if filename.startswith(files_blobstore._BLOBSTORE_DIRECTORY):
__checkIsFinalizedName(filename)
blobkey = files_blobstore.get_blob_key(filename)
if blobkey:
blobkeys.append(blobkey)
elif filename.startswith(gs._GS_PREFIX):
__checkIsFinalizedName(filename)
blobkeys.append(blobstore.create_gs_key(filename))
else:
raise InvalidFileNameError('Filename should start with /%s or /%s' %
(files_blobstore._BLOBSTORE_DIRECTORY,
gs._GS_PREFIX))
try:
blobstore.delete(blobkeys)
except Exception, e:
raise IOError('Blobstore failure.', e)