我目前将一堆.docx文件存储在GAE Blobstore中。我最近发现这些文件在某些计算机上(例如Windows 7的IE 9)下载时没有文件扩展名,但在其他计算机上(如IE 8,Windows 7的Chrome)可以正常工作。
以下是文件在Blobstore中的存储方式:
以下是从Chrome检查器中获取的该文件的响应头信息:
这是我如何提供 Blob 服务的方法:
以下是文件在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)
self.send_blob(blob_info, save_as=blob_info.filename)
。 - kennysongfilename
不包括文件扩展名('doc1' 而不是 'doc1.docx')。我假设content_type
标头会处理这个问题(因为它在大多数浏览器上都可以正常工作)。这可能是问题的源头吗? - kennysong