5
我目前在GAE Blobstore中存储了一堆.docx文件。我最近注意到这些文件在某些计算机(IE 9 for Windows 7)上没有文件扩展名的情况下下载,但对其他计算机(IE 8,Chrome for Windows 7)可以正常工作。GAE从blobstore下载的文件扩展名
这里的文件如何存储在Blob存储区:
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的? send_blob? –
是的,我正在使用'self.send_blob(blob_info,save_as = blob_info.filename)' – kennysong
您可以发布实际计算'filename'的代码,以确保它具有扩展名。另外,您可以使用BlobInfo检查文件名是否以正确的扩展名存储。 –