擅长:python、mysql、java
<p>根据以上用户voscausa的评论,我改变了文件下载的方案,即使用Blobstore来服务文件下载。现在解决了内存泄漏问题。在</p>
<p>参考号:<a href="https://cloud.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage" rel="nofollow">https://cloud.google.com/appengine/docs/python/blobstore/#Python_Using_the_Blobstore_API_with_Google_Cloud_Storage</a></p>
<pre><code>from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
class GCSServingHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
read_path = "/path/to/gcs file/" # The leading chars should not be "/gs/"
blob_key = blobstore.create_gs_key("/gs/" + read_path)
f_name = "file name"
f_type = "file type" # Such as 'text/plain'
self.response.headers['Content-Type'] = f_type
self.response.headers['Content-Disposition'] = "attachment; filename=\"%s\";"%f_name
self.response.headers['Content-Disposition'] += " filename*=utf-8''" + urllib2.quote(f_name.encode("utf8"))
self.send_blob(blob_key)
</code></pre>