Skip to content

Instantly share code, notes, and snippets.

@christophchamp
Created October 2, 2013 05:26
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 christophchamp/6789446 to your computer and use it in GitHub Desktop.
Save christophchamp/6789446 to your computer and use it in GitHub Desktop.
This simple script will change/update the Content-Type for all objects in our Rackspace Cloud Files container.
#!/usr/bin/python
import os
import pyrax
YOUR_USERNAME=""
YOUR_API_KEY=""
YOUR_REGION="" # E.g., "ORD", "DFW", etc.
YOUR_CONTAINER_NAME=""
#pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_credentials(YOUR_USERNAME, YOUR_API_KEY, region=YOUR_REGION)
cf = pyrax.connect_to_cloudfiles(public=True)
for obj in cf.get_container_object_names(YOUR_CONTAINER_NAME):
file_name, file_extension = os.path.splitext(str(obj))
if file_extension == '.jpg':
cf.change_object_content_type(YOUR_CONTAINER_NAME, str(obj),
"image/jpeg", guess=False)
# Uncomment the following line if you want pyrax to try to guess the
# the correct Content-Type (note: You will, of course, want to comment
# out the "if file_extension" part above if you use the following line)
#cf.change_object_content_type(YOUR_CONTAINER_NAME, str(obj), guess=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment