Rackspace - 如何获取Container的URL和文件.net

时间:2013-08-06 11:25:08

标签: rackspace

我使用Rackspace上传文件容器中的文件。请建议如何将文件上传到服务器并访问URL

1 个答案:

答案 0 :(得分:5)

创建有效的Rackspace帐户 创建一个新容器来保存您需要保存的文件

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;
    }

然后通过设置CDN Enabled

使公共容器可用
var cloudIdentity = new CloudIdentity() { APIKey = strAPIKey, Username = strUserName };
var cloudFilesProvider = new CloudFilesProvider(cloudIdentity);
cloudFilesProvider.EnableCDNOnContainer(strContainerName, false);

获取容器的公共URL

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

然后使用此URL和上传文件的文件名公开访问该文件