Skip to content

Instantly share code, notes, and snippets.

@untitaker
Created November 25, 2012 09:23
Show Gist options
  • Save untitaker/4142919 to your computer and use it in GitHub Desktop.
Save untitaker/4142919 to your computer and use it in GitHub Desktop.
# mitsuhiko/flask#637
from flask import send_file, Flask, request
import datetime
app = Flask(__name__)
@app.route('/image/<file_id>')
def images(file_id):
f = open('lel.jpg') # some jpeg file in the same dir
rv = send_file(f,
mimetype='image/jpg',
# as_attachment=True,
attachment_filename='lel.jpg',
add_etags=False,
conditional=True
)
rv.last_modified = datetime.datetime.strptime('2012-11-24 08:51:27', '%Y-%m-%d %H:%M:%S')
app.logger.debug(rv.last_modified) # 2012-11-24 08:51:27
app.logger.debug(request.if_modified_since) # 2012-11-24 08:51:27
#app.logger.debug(rv.last_modified<=request.if_modified_since) # True
return rv
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment