ken*_*ong 5 google-app-engine internet-explorer google-chrome http-headers blobstore
我目前正在GAE Blobstore中存储一堆.docx文件.我最近注意到这些文件在某些计算机(IE 9 for Windows 7)上没有文件扩展名下载,但适用于其他人(IE 8,Chrome for Windows 7).
以下是文件存储在blobstore中的方式:
f = files.blobstore.create(mime_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
_blobinfo_uploaded_filename=filename)
## then some code to write data and save ##
Run Code Online (Sandbox Code Playgroud)
以下是Chrome检查器中文件的响应标头:
Cache-Control:no-cache
Content-Disposition:attachment; filename="causes_of_ww1_emanresu"
Content-Length:12120
Content-Type:application/vnd.openxmlformats-officedocument.wordprocessingml.document
Date:Fri, 26 Oct 2012 23:54:09 GMT
Server:Google Frontend
X-AppEngine-Estimated-CPM-US-Dollars:$0.000033
X-AppEngine-Resource-Usage:ms=15 cpu_ms=0
Run Code Online (Sandbox Code Playgroud)
这是我如何服务blob:
self.send_blob(blob_info, save_as=blob_info.filename, content_type=blob_info.content_type)
Run Code Online (Sandbox Code Playgroud)
我甚至尝试过硬编码content_type='application/vnd.openxmlformats-officedocument.wordprocessingml.document'无济于事.
关于发生了什么以及如何解决问题的任何想法?
根据要求,这是我在最初保存blob时如何获取文件信息.我很确定在这个级别上没有出现错误,但这是问题的前兆:
# get the file from a file_url with urlfetch
result = urlfetch.fetch(file_url)
headers = result.headers
# some custom functions to return a filename
username = self.get_username()
filename = get_filename(title, username)
# write the file to blobstore
f = files.blobstore.create(mime_type=headers['content-type'],
_blobinfo_uploaded_filename=filename)
with files.open(f, 'a') as data:
data.write(result.content)
files.finalize(f)
blob_key = files.blobstore.get_blob_key(f)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
337 次 |
| 最近记录: |