我正在使用 Rackspace 在文件容器中上传文件。请建议如何将文件上传到服务器并访问 URL
问问题
1017 次
1 回答
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 和文件名来公开访问文件
于 2013-08-06T11:29:17.723 回答