我无法从 rackspace 云创建子文件夹/子容器。我需要一个像 MAINFOLDER/SUBFOLDER/FileName 这样的结构。有人可以帮助我创建子文件夹。这是创建容器并将文件保存到机架空间云的代码。
例如:http : //abc123.r27.cf1.rackcdn.com/main/sub/test.png http://abc123.r27.cf1.rackcdn.com/main/test.png
public string SaveFiles(string ContainerName, string FileName, Byte[] Content) { try { if (Content == null) throw new Exception("Content 参数为空。它必须是一个字节数组。"); if (Content.Length == 0) throw new Exception("Content 参数无效。它不能是零长度数组。");
MemoryStream ms = new MemoryStream(Content);
Container container = CreateContainer(ContainerName, true);
var obj = new CF_Object(CFConnection, container, CFClient, FileName);
obj.Write(ms);
if (string.IsNullOrEmpty(obj.CdnSslUri.ToString()))
return obj.CdnUri.ToString();
else
return obj.CdnSslUri.ToString();
}
catch
{
throw;
}
}
public Container CreateContainer(string ContainerName, bool makePublic) { try { var account = new CF_Account(CFConnection, CFClient); var list = account.GetContainers(true);
var IsFound = from objList in list
where objList.Name == ContainerName
select objList;
if (IsFound.Count() <= 0)
{
Container container = account.CreateContainer(ContainerName);
if (makePublic)
container.MakePublic();
return container;
}
else
{
return new CF_Container(CFConnection, CFClient, ContainerName);
}
}
catch (Exception ex)
{
throw ex;
}
}