-
Notifications
You must be signed in to change notification settings - Fork 27
Rackspace Cloud Files Code Samples
Here we will provide samples for basic operation on CloudFilesProvider
.
CloudServersProvider
requries we pass in CloudIdentity
. We can create CloudIdentity
by passing any 2 combination Username/Password or Username/APIKey.
var cloudIdentity = new CloudIdentity() { Username = "username", Password = "password" };
or
var cloudIdentity = new CloudIdentity() { APIKey = "apikey", Username = "username" };
For more information on IdentityProvider
There are 2 ways to pass in the identity credentials to CloudFilesProvider
:
-
In the constructor.
-
Into each method individually.
Our samples below will assume the identity has been passed into the constructor.
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
ObjectStore createContainerResponse = cloudFilesProvider.CreateContainer("Container Name");
Note: If you don't pass in region, default region is assumed. Here is an example with region.
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
ObjectStore createContainerResponse = cloudFilesProvider.CreateContainer("Container Name",region:"DFW");
Check the createContainerResponse
for status ObjectStore.ContainerCreated
for container creation.
Here are the ObjectStore
values.
Unknown
ContainerCreated
ContainerExists
ContainerDeleted
ContainerNotEmpty
ContainerNotFound
ObjectDeleted
ObjectCreated
ObjectPurged
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
ObjectStore containerDeleteResponse = cloudFilesProvider.DeleteContainer("Container Name");
Check the containerDeleteResponse
for status ObjectStore.ContainerDeleted
for container deletion.
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
IEnumerable<Container> containerList = cloudFilesProvider .ListContainers();
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
IEnumerable<Container> containerList = cloudFilesProvider.ListContainers(region:"ord");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
IEnumerable<ContainerObject> containerObjectList = cloudFilesProvider.ListObjects("container name");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.EnableCDNOnContainer("container name");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.DisableCDNOnContainer("container name");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.EnableStaticWebOnContainer("container name", "web index", "web error", "web listings css", "web listing");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.DisableStaticWebOnContainer("container name");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
var fileName = "file_name.jpg";
using(var stream = System.IO.File.OpenRead("c:\filepath\file_name.jpg")){
cloudFilesProvider.CreateObject("container name", stream, "object_save_name.jpg");
}
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.CreateObjectFromFile("container name", @"c:\directory\test.jpg", "test.jpg");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.GetObjectSaveToFile("container name", @"c:\\save Directory\\", "test.jpg");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
ObjectStore deleteObjectResponse = cloudFilesProvider.DeleteObject("container name", "test.jpg");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
ObjectStore copyObjectResponse = cloudFilesProvider.CopyObject("source container name", "source object name", "destination container name", "destination object name");
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
ObjectStore copyObjectResponse = cloudFilesProvider.CopyObject("source container name", "source object name", "destination container name", "destination object name", useInternalUrl:true);
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.PurgeObjectFromCDN("container name", "object name");
##Troubleshooting
There is a possibility that default region is not set for your account. Try passing in the optional region parameter.
For example:
cloudFileProvider.ListContainers(region: “DFW”);