* .docx文件位于“流”中-不能由MS Word打开

时间:2018-10-02 19:13:23

标签: python web2py docx

web2py框架内部,我想以下载流的形式返回MS Word * .docx文件。我做到了,如下面的代码所示。但是,文件下载过程完成后,一个人无法在MS Word中打开它

代码:

from io import BytesIO 
filename = 'empty_file.docx'
filepath = os.path.join(request.folder, 'uploads',filename )
# read a file from file system (disk)
with open(filepath, 'rb') as f: 
    out_stream = BytesIO(f.read())
response.headers['Content-Disposition'] = "attachment; filename=%s" % filename
response.headers['Content-Type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
return out_stream.getvalue()

可能是什么问题?

当我手动下载同一文件时,我可以轻松用MS word打开它enter image description here

更新1

检查文件中发布的校验和(md5)不相等。

openssl dgst -md5 empty_file.docx
MD5(empty_file.docx)= b5be5d79e57f73303c9df9c420b64a43

enter image description here

更新2

尺寸比较

11462字节empty_file.docx-原始于网络托管。

11311个字节empty_file.docx (4)-已下载到我的PC。

邮政编码页脚

$ unzip -t empty_file.docx
Archive:  empty_file.docx
testing: [Content_Types].xml      OK
testing: _rels/.rels              OK
testing: word/_rels/document.xml.rels   OK
testing: word/document.xml        OK
testing: word/theme/theme1.xml    OK
testing: word/settings.xml        OK
testing: word/fontTable.xml       OK
testing: word/webSettings.xml     OK
testing: docProps/app.xml         OK
testing: docProps/core.xml        OK
testing: word/styles.xml          OK
No errors detected in compressed data of empty_file.docx.

但是我仍然不知道如何解决它...

0 个答案:

没有答案