rackspace/pyrax — pull request #27 by ExtremeSitting (2013-03-07 12:58:34+00:00)
Title: Feature addition: Change content-type

The Cloud Files API supports updating an object's content-type with the COPY verb or using the PUT verb with the X-Copy-From: header and supplying a new content-type. This has been immensely useful to me when fixing objects that got uploaded an via the legacy Cloud Files file manager and with odd files in general.

Here is an extreme example of using the method to change the content-type of an object and then allowing the mimetype to be guessed and adjusted:

```python
for obj in cf.get_container_objects('blar'):
print obj.name, obj.content_type
cf.change_object_content_type('blar', obj.name, 'something/else')
print obj.name, cf.get_object(obj.container, obj.name).content_type
cf.change_object_content_type('blar', obj.name, None, guess=True)
print obj.name, cf.get_object(obj.container, obj.name).content_type
print '\n'
```

Output:

Doom.bat application/x-msdos-program
Out[43]: 'e9f831793d0b46d7803ddddd5bafae48'
Doom.bat something/else
Out[43]: 'e9f831793d0b46d7803ddddd5bafae48'
Doom.bat application/x-msdos-program

Fraud-Hunting-101.pdf application/pdf
Out[43]: '1e5b2391b11b145846d25ace0a254b69'
Fraud-Hunting-101.pdf something/else
Out[43]: '1e5b2391b11b145846d25ace0a254b69'
Fraud-Hunting-101.pdf application/pdf

Get.png image/png
Out[43]: 'af68cbcbddf87ebb267735a17510bc4b'
Get.png something/else
Out[43]: 'af68cbcbddf87ebb267735a17510bc4b'
Get.png image/png

LLNW_network_map.jpeg image/jpeg
Out[43]: 'fec8063ada5170dc88f543bc4dbb541f'
LLNW_network_map.jpeg something/else
Out[43]: 'fec8063ada5170dc88f543bc4dbb541f'
LLNW_network_map.jpeg image/jpeg