A little Extra info for the Java Test Application
Unlike scripting languages like Ruby or Python. You have to build the sources and add all the JAR's and additional class files you need to use at compile time; like including the Apache HTTP Commons stuff. You can either do this using the --classpath option with javac but, it can become a dependency nightmare. I highly recommend using an IDE like Eclipse or Netbeans and adding the sources to your buildpaths. Also note that during compilation there is a cloudfiles.properties file that must be added to the buildpath. If you have any other questions please feel free to shoot us an email at cloudfiles@rackspacecloud.com
Simple Java Application
package com.rackspacecloud.test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.httpclient.HttpException;
import com.rackspacecloud.client.cloudfiles.FilesClient;
public class Cftest {
public static void main(String[] args) throws HttpException, IOException {
FilesClient client = new FilesClient("UserNameGoesHere", "APIKeyGoesHere");
client.login();
client.createContainer("ContainerNameGoesHere");
File f = new File("PathToFileGoesHere");
client.storeObject("ContainerNameGoesHere", f, "Content Type");
}
}
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

13 Comments
Which jar i need to download ? Are they free source?
Login failure.
It is not working for me. Same program when i run i got this exception.
com.rackspacecloud.client.cloudfiles.FilesAuthorizationException: You must be logged in
So, please help.
Thank You.
Re: Exception
Null Pointer Exception
When I call client.login(), I get:
Exception in thread "main" java.lang.NullPointerException
at java.net.URI$Parser.parse(URI.java:3004)
at java.net.URI.<init>(URI.java:577)
at java.net.URI.create(URI.java:839)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
at com.rackspacecloud.client.cloudfiles.FilesClient.login(FilesClient.java:270)
Any help would be greatly appreciated.
Thanks.
re: error
Fixes to example code
Here is the complete code
package com.rackspacecloud.test;
import java.io.File;
import java.io.IOException;
import org.apache.commons.httpclient.HttpException;
import com.rackspacecloud.client.cloudfiles.FilesClient;
public class Cftest {
public static void main(String[] args) throws HttpException, IOException {
FilesClient client = new FilesClient("UserNameGoesHere", "APIKeyGoesHere");
client.setAuthenticationURL("https://auth.api.rackspacecloud.com/v1.0");
client.setConnectionTimeOut(5000); //time in ms
client.login();
client.createContainer("ContainerNameGoesHere");
File f = new File("PathToFileGoesHere");
client.storeObject("ContainerNameGoesHere", f, "Content Type");
}
}
I believe their internal
setting headers?
Thanks.
re: headers
http://docs.rackspace.com/files/api/v1/cf-devguide/content/Update_Object_Metadata-d1e2338.html
re: headers
Map<String,String> metadata = new HashMap<String,String>();
metadata.put("X-Delete-After", "120");
rackspaceFilesClient.storeStreamedObject(RACKSPACE_CONTAINER, new ByteArrayInputStream(decodedPage.getBytes("UTF-8")), RACKSPACE_MIME_TYPE, filename, metadata);
re: headers
bloatware apis
re: api
<dependencies>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>cloudfiles-us</artifactId>
<version>1.5.5</version>
</dependency>
</dependencies>
That will bring in the minimum number of dependencies to work with Cloud Files US (use artifactId cloudfiles-uk for Cloud Files UK).
Add new comment