Created
October 2, 2013 05:26
-
-
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.
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
#!/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