title: How to send zip files in the python Flask framework?
body: <p>I have a flask server that grabs binary data for several different files from a database and puts them into a python 'zipfile' object.  I want to send the generated zip file with my code using flask's "send_file" method.</p>
  
  <p>I was originally able to send non-zip files successfully by using the BytesIO(bin) as the first argument to send_file, but for some reason I can't do the same thing with my generated zip file.  It gives the error:</p>
  
  <p>'ZipFile' does not have the buffer interface.</p>
  
  <p>How do I send this zip file object to the user with Flask?</p>
  
  <p>This is my code:</p>
  
  <pre><code>@app.route("/getcaps",methods=['GET','POST'])
  def downloadFiles():
      if request.method == 'POST':
          mongo = MongoDAO('localhost',27017)
          identifier = request.form['CapsuleName']
          password = request.form['CapsulePassword']
          result = mongo.getCapsuleByIdentifier(identifier,password)
          zf = zipfile.ZipFile('capsule.zip','w')
          files = result['files']
          for individualFile in files:
              data = zipfile.ZipInfo(individualFile['fileName'])
              data.date_time = time.localtime(time.time())[:6]
              data.compress_type = zipfile.ZIP_DEFLATED
              zf.writestr(data,individualFile['fileData'])
          return send_file(BytesIO(zf), attachment_filename='capsule.zip', as_attachment=True)
      return render_template('download.html')
  </code></pre>