在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()
可能是什么问题?
检查文件中发布的校验和(md5)不相等。
openssl dgst -md5 empty_file.docx
MD5(empty_file.docx)= b5be5d79e57f73303c9df9c420b64a43
尺寸比较
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.
但是我仍然不知道如何解决它...