Created
February 23, 2016 23:03
-
-
Save astewart-twist/e835c6289d5017ee06a6 to your computer and use it in GitHub Desktop.
flask s3 proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@route('/static/<path:path>') | |
def static_proxy(path): | |
conn = boto.s3.connection.S3Connection(ACCESS_KEY, SECRET_ACCESS_KEY) | |
bucket = conn.get_bucket(BUCKET_NAME, validate=False) | |
key = boto.s3.key.Key(bucket) | |
key.key = path | |
try: | |
key.open_read() | |
headers = dict(key.resp.getheaders()) | |
return Response(key, headers=headers) | |
except boto.exception.S3ResponseError as e: | |
return flask.Response(e.body, status=e.status, headers=key.resp.getheaders()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can i download , multiple files using this?