Skip to content

Instantly share code, notes, and snippets.

@dustin

dustin/redirector.py

Created Jul 19, 2011
Embed
What would you like to do?
S3 temporary link maker
#!/usr/bin/env python
import sys
import BaseHTTPServer
import boto.s3
from boto.s3.key import Key
PORT = 8123
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
s3 = boto.connect_s3()
s3bucket = s3.get_bucket('photo.west.spy.net')
k = Key(s3bucket)
k.key = self.path[1:]
dest = k.generate_url(60, force_http=True)
self.send_response(302)
self.send_header('Location', dest)
self.end_headers()
self.wfile.write(dest)
if __name__ == '__main__':
httpd = BaseHTTPServer.HTTPServer(("", PORT), MyHandler)
print "serving at port", PORT
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.