Skip to content

Instantly share code, notes, and snippets.

@chiragchamoli
Created July 14, 2018 09:11
Show Gist options
  • Save chiragchamoli/451de8b8aa5cbf32739fe7f96323fc16 to your computer and use it in GitHub Desktop.
Save chiragchamoli/451de8b8aa5cbf32739fe7f96323fc16 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