title: plotly dash download bytes stream
body: <p>I have an app that produces a zip file that I want to download using dcc.download. I think the zip-creation works fine (I tested it by downloading it directly using &quot;with&quot;). But how its possible to download the stream <code>archive</code> using dcc.download? How do I have to hand it over the correct way?</p>
  <p>My code below:</p>
  <pre><code>import io
  from os import close
  import dash
  from dash.dependencies import Output, Input
  from dash_extensions.snippets import send_bytes
  import dash_html_components as html
  import dash_core_components as dcc
  import base64
  
  import matplotlib.pyplot as plt
  import zipfile
  from io import BytesIO
  
  app = dash.Dash(prevent_initial_callbacks=True)
  app.layout = html.Div([html.Button(&quot;Download zip&quot;, id=&quot;btn_txt&quot;), 
                         dcc.Download(id=&quot;download-text&quot;)]
                       )
  
  @app.callback(
      Output(&quot;download-text&quot;, &quot;data&quot;),
      Input(&quot;btn_txt&quot;, &quot;n_clicks&quot;),
      prevent_initial_call=True,
  )
  def func(n_clicks):
      archive = BytesIO()
      
      with zipfile.ZipFile(archive, mode=&quot;w&quot;) as zf:
          for i in range(3):
              plt.plot([i, i])
              buf = io.BytesIO()
              plt.savefig(buf)
              plt.close()
              img_name = &quot;fig_{:02d}.png&quot;.format(i)
              zf.writestr(img_name, buf.getvalue())
      
      return send_bytes(archive.read(), &quot;some_name.zip&quot;)
  
  
  
  if __name__ == &quot;__main__&quot;:
      app.run_server(debug=False)
  </code></pre>