Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This simple script will change/update the Content-Type for all objects in our Rackspace Cloud Files container.
import os
import pyrax
YOUR_REGION="" # E.g., "ORD", "DFW", etc.
#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