使用blobstore存储MIME类型



如何将传入blob的MIME类型存储到blobstore?我现在既不能获得名称,也不能获得使用处理程序blobstore_handlers.BlobstoreUploadHandler所存储的MIME类型。这是我的代码,不使用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 = files.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)

name和mime type都可以作为参数传递,以创建:

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.
  """

最新更新