storing MIME type with blobstore
How can I also store the MIME type of incoming blobs to the blobstore? I now neither get the name nor the MIME type stored which using the handler blobstore_handlers.BlobstoreUploadHandler
it can. Here's my code that doesn't use blobstore_handlers.BlobstoreUploadHandler
:
def create_image(number, self, file, ad):
logging.debug('creating image')
try:
file_name = files.blobstore.create()
with files.open(file_name, 'a') as f:
f.write(file)
files.finalize(file_name)
blob_key = f开发者_运维技巧iles.blobstore.get_blob_key(file_name)
logging.debug('creating image')
img = Image(reference=ad)
logging.debug('creating image')
img.primary_image = blob_key
logging.debug('creating image')
img.put()
ad.put()
except Exception:
self.response.write(Exception)
Both name and mime type can be passed as arguments to create:
def create(mime_type='application/octet-stream',
_blobinfo_uploaded_filename=None):
"""Create a writable blobstore file.
Args:
mime_type: Resulting blob content MIME type as string.
_blobinfo_uploaded_filename: Resulting blob's BlobInfo file name as string.
Returns:
A file name for blobstore file. This file can be opened for write
by File API open function. To read the file or obtain its blob key, finalize
it and call get_blob_key function.
"""
精彩评论