Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rackspace - how to get URL of Container and file .net

Tags:

rackspace

I am using Rackspace to upload files in file container. Please suggest how to upload the file to Server and access the URL

like image 548
Liya S Avatar asked Aug 06 '13 11:08

Liya S


1 Answers

Create an Valid Rackspace account Create a New container to save the files you need to keep

public bool CreateNewContainer(string strContainerName)
    {
        bool isSuccess = false;
        try
        {
            var cloudIdentity = new CloudIdentity() { APIKey = strAPIKey, Username = strUserName };
            var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
            ObjectStore createContainerResponse = cloudFilesProvider.CreateContainer(strContainerName);
            if (createContainerResponse == ObjectStore.ContainerCreated || createContainerResponse == ObjectStore.ContainerExists)
            {
                isSuccess = true;
            }
        }
        catch (Exception)
        { }
        return isSuccess;
    }

Then make the container publically available by setting CDN Enabled

var cloudIdentity = new CloudIdentity() { APIKey = strAPIKey, Username = strUserName };
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.EnableCDNOnContainer(strContainerName, false);

Get the public URL of container

var cloudIdentity = new CloudIdentity() { APIKey = strAPIKey, Username = strUserName };
            var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
            ContainerCDN strCdnURL = cloudFilesProvider.GetContainerCDNHeader(strContainerName);
            string returnURL = strCdnURL.CDNUri

Then use this URL and file name of uploaded file to access the file publicly

like image 74
Prem Singh Avatar answered Oct 08 '22 05:10

Prem Singh