Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从AppEngine中的blob接收静态URL_Python_Google App Engine_Blobstore - Fatal编程技术网

Python 从AppEngine中的blob接收静态URL

Python 从AppEngine中的blob接收静态URL,python,google-app-engine,blobstore,Python,Google App Engine,Blobstore,在我的应用程序中,我正在创建一个blob,该blob已正确上载到应用程序引擎仪表板中。但是,此创建的文件需要通过电子邮件发送给相应的人。为了做到这一点,我要么需要文件本身作为附件,要么需要一个静态URL,供此人下载。我不知道如何从blobkey获取静态URL 这是创建文件的代码,但没有什么特别之处: file_name = files.blobstore.create(mime_type='text/csv') with files.open(file_name, 'a') as f:

在我的应用程序中,我正在创建一个blob,该blob已正确上载到应用程序引擎仪表板中。但是,此创建的文件需要通过电子邮件发送给相应的人。为了做到这一点,我要么需要文件本身作为附件,要么需要一个静态URL,供此人下载。我不知道如何从blobkey获取静态URL

这是创建文件的代码,但没有什么特别之处:

    file_name = files.blobstore.create(mime_type='text/csv')
with files.open(file_name, 'a') as f:
  f.write(dataset)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name)
blob_info = blobstore.BlobInfo.get(blob_key)

new_url = blob_key.urlsafe()

如果你想提供文件,请查看

如果要将其作为附件发送,请参阅。您将需要重新安装,然后将其附加到邮件中

from google.appengine.ext import blobstore

# blob_key = ...

# Instantiate a BlobReader for a given Blobstore value.
blob_reader = blobstore.BlobReader(blob_key)

# 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_contents = blob_reader.read()

如果你想提供文件,请查看

如果要将其作为附件发送,请参阅。您将需要重新安装,然后将其附加到邮件中

from google.appengine.ext import blobstore

# blob_key = ...

# Instantiate a BlobReader for a given Blobstore value.
blob_reader = blobstore.BlobReader(blob_key)

# 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_contents = blob_reader.read()
看看,它们很好地解释了如何检索和使用Blobstore条目。以下是文档中的示例

from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, resource):
    resource = str(urllib.unquote(resource))
    blob_info = blobstore.BlobInfo.get(resource)
    self.send_blob(blob_info)
看看,它们很好地解释了如何检索和使用Blobstore条目。以下是文档中的示例

from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, resource):
    resource = str(urllib.unquote(resource))
    blob_info = blobstore.BlobInfo.get(resource)
    self.send_blob(blob_info)

我的用例不同,但我通过查找url路径来提供blobstore中的静态内容。下面是模型和get函数

class StaticContent(db.Model):
    body = db.BlobProperty()
    content_type = db.StringProperty()
    last_modified = db.DateTimeProperty(required=True, auto_now=True)
    etag = aetycoon.DerivedProperty(lambda x: hashlib.sha1(x.body).hexdigest())

def get(path):  
    return StaticContent.get_by_key_name(path)
您可以在屏幕上看到我的wepapp2处理程序


有关详细说明,您也可以查看。

我的用例不同,但我通过查找url路径来提供blobstore中的静态内容。下面是模型和get函数

class StaticContent(db.Model):
    body = db.BlobProperty()
    content_type = db.StringProperty()
    last_modified = db.DateTimeProperty(required=True, auto_now=True)
    etag = aetycoon.DerivedProperty(lambda x: hashlib.sha1(x.body).hexdigest())

def get(path):  
    return StaticContent.get_by_key_name(path)
您可以在屏幕上看到我的wepapp2处理程序

有关详细解释,您也可以查看。

忽略我(已删除)的答案。这个答案和它的链接解释了一切。忽略我的(删除的)答案。这个答案和它的链接解释了一切。