Skip to content

Instantly share code, notes, and snippets.

@evan4498
Last active December 18, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evan4498/5760758 to your computer and use it in GitHub Desktop.
Save evan4498/5760758 to your computer and use it in GitHub Desktop.
Create temp url
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2013 Rackspace
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
import pyrax
cls = pyrax.utils.import_class('pyrax.identity.rax_identity.RaxIdentity')
pyrax.identity = cls()
pyrax.set_credentials("USERNAME", "API_KEY")
cf = pyrax.cloudfiles
print "--------------------------------------------------"
cont = cf.get_container("iso")
files = cont.get_object_names()
for pos, filename in enumerate(files):
print "%s: %s" % (pos, filename)
print ""
filenum = int(raw_input("What file do you want to serve up? "))
filename = files[filenum]
print "Serving file:", filename
print ""
time = int(raw_input("How many minutes should this file be served for? "))
secs = time * 60
print ""
my_key = "MAKE UP A KEY OF AT LEAST 10 LETTERS AND DIGITS"
cf.set_temp_url_key(my_key)
tempurl = cf.get_temp_url(cont.name, filename , seconds=secs, method="GET")
print "Temporary URL is: "
print tempurl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment