Rackspace Cloud Upload with PHP API – Troubleshooting
4 Apr
You may have seen our previous blog post here for uploading files to Rackspace Cloud using the PHP API. Despite the relatively easy script it wasn’t plain sailing for us and we had to troubleshoot a number of errors. We wanted to share our fixes with you as we couldn’t find any resolutions on Google.
The first error we got was;
Fatal error: Uncaught exception 'InvalidResponseException' with message 'Unexpected response (): ' in /home/uname/public_html/rackspaceupload/cloudapi/cloudfiles.php:206 Stack trace: #0 /home/uname/public_html/rackspaceupload/upload.php(12): CF_Authentication->authenticate() #1 {main} thrown in /home/uname/public_html/rackspaceupload/cloudapi/cloudfiles.php on line 206
Now from the error message you would assume that it has something to do with your username or API key due to it mentioning the authentication function. Although if it was an issue with authentication you would probably see ‘AuthenticationException’ as the exception. In this case we found that Curl Open SSL was not installed despite having Curl installed. So ask your server administrator to install it for you if you receive this error.
Another big error we got was;
Fatal error: Uncaught exception 'BadContentTypeException' with message 'Required Content-Type not set' in /home/uname/public_html/rackspaceupload/cloudapi/cloudfiles.php:1645 Stack trace: #0 /home/uname/public_html/rackspaceupload/cloudapi/cloudfiles.php(1962): CF_Object->_guess_content_type('/tmp/phpyese5G') #1 /home/uname/public_html/rackspaceupload/upload.php(19): CF_Object->load_from_filename('/tmp/phpyese5G') #2 {main} thrown in /home/uname/public_html/rackspaceupload/cloudapi/cloudfiles.php on line 1645
This error took us a very long time to figure out, with some help from Rackspace Support we finally reached a resoltuion. We solved this by doing two things, first we installed the PECL Fileinfo Module, this module is to get file information, we the needed to install the PHP module ‘mod_mime_magic’. This then solved this issue and we can now upload to Rackspace Cloud.
Got another error? Having trouble resolving these errors? Fell free to leave a comment below and we will offer you any advice that we can.
We accept no responsibility for anything that happens to your server if you follow our advice, we are just supplying you with information on how we solved these issues.

I solved the first error finally by downloading the certificate and renaming it what cURL was looking for.
After checking all the SSL and cURL stuff, it was all right. Downloading the cert and renaming it did the trick for us:
cd /usr/local/share
mkdir curl
cd curl
wget “http://curl.haxx.se/docs/caextract.html”
ln cacert.pem curl-ca-bundle.crt
Thanks for that randulo. I’m sure it wil be useful to someone.
When you say, “…with some help from Rackspace Support we finally reached a resoltuion”, do you have a managed solution with them that provides some kind of extra support? I currently have quite a few of there cloud servers and ran into this same problem while trying to create a mysql backup to cloudfiles script. My first instinct was to start a live chat and see if had saw the error before and could point me to the right solution. The answer I got reminded me of those ‘help’ channels on IRC. He replied they weren’t developers and basically told me to go RTFM giving me the link to the API page.
@Tyler
No we do not have any extra managed support but we did submit our query via support ticket rather than live chat.
When submitting a ticket we got a reply from ‘Jeff Pierce – Linux Administrator II, RHCE’, and things that he suggested lead to us towards finding a solution.
We had curl and openssl installed so I did what randulo talked about. It did not work. We had to modify it some.
After opening the cloudfile.php we found a comment within it to use $auth->ssl_use_cabundle();.
We attempted it with no input value with no results, so we changed it to ssl_use_cabundle”/usr/local/share/curl/”), which did nothing for us, after that we changed it to ssl_use_cabundle(“/usr/local/share/curl/curl-ca-bundle.crt”) which got it to complain about another cert location: /etc/ssl/certs
we removed the ssl_use_cabundle method call from our code and setup a symbolic link: ln /usr/local/share/curl/cacert.pem /etc/ssl/certs/ca-certificates.crt
That did the trick for us!
Thx for this great information that you are sharing with us!!!