Skip to content

Instantly share code, notes, and snippets.

@chiragchamoli
Created September 9, 2018 14:39
Show Gist options
  • Save chiragchamoli/cfcb53a49a790c70cd56ecf2f1c9d76b to your computer and use it in GitHub Desktop.
Save chiragchamoli/cfcb53a49a790c70cd56ecf2f1c9d76b to your computer and use it in GitHub Desktop.
Upload a StringIO object with send_file
#!/usr/bin/env python
# Thanks to Dan Jacob for a part of the code !
from flask import Flask, send_file
import StringIO
app = Flask(__name__)
@app.route('/')
def index():
strIO = StringIO.StringIO()
strIO.write('Hello from Dan Jacob and Stephane Wirtel !')
strIO.seek(0)
return send_file(strIO,
attachment_filename="testing.txt",
as_attachment=True)
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment