0
私は現在以下のコードを使用して単語文書を生成し、cherrypyを使用してこれをWeb上で提供しています。ジップとサーバーの複数メモリ内ファイル
tpl.get_docx().save(iostream)
cherrypy.response.headers['Content-Type'] = (
'application/vnd.openxmlformats-officedocument'
'.wordprocessingml.document'
)
cherrypy.response.headers['Content-Disposition'] = (
'attachment; filename={fname}.docx'.format(
fname='SP' + kwargs['sp'] + '-'+ kwargs['WO'] + ' ' + kwargs['site'] + ' - ' + 'RPC Report' +'.docx'
)
)
iostream.seek(0)
return file_generator(iostream)
さらにドキュメントを作成し、メモリで圧縮してWeb上で提供する予定です。どのようにこれがimplmentedことができる、私はzipfileライブラリを使用してみました、それは複雑なメモリ内のファイルを圧縮しているようです。
次の例ではGoogleの問題を解決するかもしれませんが、使用方法はわかりません。
import zipfile
import StringIO
zipped_file = StringIO.StringIO()
with zipfile.ZipFile(zipped_file, 'w') as zip:
for i, file in enumerate(files):
file.seek(0)
zip.writestr("{}.csv".format(i), file.read())
zipped_file.seek(0)
をこの作業を持って... – 576i