gpt4 book ai didi

internet-explorer - GAE 从 blobstore 下载文件扩展名

转载 作者:太空宇宙 更新时间:2023-11-03 15:25:19 25 4
gpt4 key购买 nike

我目前正在 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 ##

这是来自 Chrome 检查器的文件的响应 header :

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)

最佳答案

啊,根据顶部的评论,解决方案是将文件扩展名添加到 BlobInfo 的文件名属性中。我最初没有意识到这是必要的,因为 Chrome 在下载时会自动添加文件扩展名。

关于internet-explorer - GAE 从 blobstore 下载文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13095944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com