繁体   English   中英

如何使用Rackspace创建/上传到子容器?

[英]How to create/upload to sub containers with Rackspace?

如何创建子容器(目录)并使用Rackspace OpenNetStack SDK上载它们? 我尝试在创建子容器时添加"\\" ,但是实际上创建了一个名为folder\\subfolder的容器,因为在OpenNetStack SDK中找不到如何添加子容器的任何地方。 即使这样,手动创建子容器也不会太困难..但是,将其上传到子容器又如何呢?

有谁知道另一个允许创建/上传到子容器的Rackspace库?

你很亲密! 技巧是在对象名称而不是容器名称中放置URL路径分隔符/ 这就是OpenStack ObjectStorage API的工作方式,并不特定于.NET SDK或Rackspace。

在下面的示例控制台应用程序中,我创建一个images容器,然后通过将文件命名为thumbnails/logo.png将文件添加到该容器的子目录中。 打印出的文件的公共URL就是容器的公共URL +文件名或http://abc123.r27.cf1.rackcdn.com/thumbnails/logo.png 容器URL对于每个容器和用户都是唯一的。

using System;
using net.openstack.Core.Domain;
using net.openstack.Providers.Rackspace;

namespace CloudFileSubdirectories
{
    public class Program
    {
        public static void Main()
        {
            // Authenticate
            const string region = "DFW";
            var user = new CloudIdentity
            {
                Username = "username",
                APIKey = "apikey"
            };
            var cloudfiles = new CloudFilesProvider(user);

            // Create a container
            cloudfiles.CreateContainer("images", region: region);

            // Make the container publically accessible
            long ttl = (long)TimeSpan.FromMinutes(15).TotalSeconds;
            cloudfiles.EnableCDNOnContainer("images", ttl, region);
            var cdnInfo = cloudfiles.GetContainerCDNHeader("images", region);
            string containerPrefix = cdnInfo.CDNUri;

            // Upload a file to a "subdirectory" in the container
            cloudfiles.CreateObjectFromFile("images", @"C:\tiny-logo.png", "thumbnails/logo.png", region: region);

            // Print out the URL of the file
            Console.WriteLine($"Uploaded to {containerPrefix}/thumbnails/logo.png");
            // Uploaded to http://abc123.r27.cf1.rackcdn.com/thumbnails/logo.png
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM