【发布时间】:2012-10-17 06:02:02
【问题描述】:
我目前在 GAE Blobstore 中存储了一堆 .docx 文件。我最近注意到,在某些计算机(Windows 7 的 IE 9)上下载这些文件时没有文件扩展名,但在其他计算机(IE 8、Windows 7 的 Chrome)上运行良好。
文件在 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 ##
这是来自 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
这是我为 blob 提供服务的方式:
self.send_blob(blob_info, save_as=blob_info.filename, content_type=blob_info.content_type)
我什至尝试硬编码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)
【问题讨论】:
-
如何将 blob 发回?发送_blob?
-
是的,我正在使用
self.send_blob(blob_info, save_as=blob_info.filename) -
您能否发布实际计算
filename的代码,以确保它具有扩展名。此外,您能否使用 BlobInfo 检查文件名是否以正确的扩展名存储。 -
没错,我只是添加了文件信息的来源。我检查了 BlobInfo,
content_type是正确的。 -
您应该确保添加扩展程序,而不是依赖浏览器为您完成。我们不会根据 MIME 类型为您执行此操作。
标签: internet-explorer google-app-engine google-chrome http-headers blobstore