Python 使用blobstore存储MIME类型

Python 使用blobstore存储MIME类型,python,google-app-engine,Python,Google App Engine,如何将传入Blob的MIME类型也存储到blobstore?现在,我既不获取名称,也不获取使用处理程序blobstore\u handlers.BlobstoreUploadHandler存储的MIME类型。这是我的代码,它不使用blobstore\u处理程序。BlobstoreUploadHandler: def create_image(number, self, file, ad): logging.debug('creating image')

如何将传入Blob的MIME类型也存储到blobstore?现在,我既不获取名称,也不获取使用处理程序
blobstore\u handlers.BlobstoreUploadHandler
存储的MIME类型。这是我的代码,它不使用
blobstore\u处理程序。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)

名称和mime类型都可以作为参数传递以创建:

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

名称和mime类型都可以作为参数传递以创建:

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

谢谢你的回复。我注意到它是在使用spec blobstoreuploadhandler时自动完成的。我想我可以用它来代替,因为我不知道如何获取MIME类型或文件名。我必须更改我的表单发布,我支持这样做。您可以从cgi.FieldStorage对象获取浏览器指定的文件名和mime类型。不过,如果您使用的是上传表单,那么使用BlobStoreUploadHandler肯定更有意义。谢谢您提供的信息。我搜索了cgi.FieldStorage,但找不到确切的方法。我将再次尝试找到如何使用cgi.FieldStorage或使用BlobstoreUploadHandler执行此操作谢谢您的回复。我注意到它是在使用spec blobstoreuploadhandler时自动完成的。我想我可以用它来代替,因为我不知道如何获取MIME类型或文件名。我必须更改我的表单发布,我支持这样做。您可以从cgi.FieldStorage对象获取浏览器指定的文件名和mime类型。不过,如果您使用的是上传表单,那么使用BlobStoreUploadHandler肯定更有意义。谢谢您提供的信息。我搜索了cgi.FieldStorage,但找不到确切的方法。我将再次尝试查找如何使用cgi.FieldStorage或使用BlobStoreUploadHandler执行此操作