简体   繁体   English

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

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

How do you create sub containers (directory) and upload them using Rackspace OpenNetStack SDK ? 如何创建子容器(目录)并使用Rackspace OpenNetStack SDK上载它们? I've tried adding "\\" when creating a sub container however it actually creates a container with the name folder\\subfolder because I cannot find anywhere in the OpenNetStack SDK on how to add a sub container. 我尝试在创建子容器时添加"\\" ,但是实际上创建了一个名为folder\\subfolder的容器,因为在OpenNetStack SDK中找不到如何添加子容器的任何地方。 Even so, creating the sub container(s) manually wouldn't be too difficult.. but what about uploading to them? 即使这样,手动创建子容器也不会太困难..但是,将其上传到子容器又如何呢?

Does anyone know of another Rackspace Library that would allow creating/uploading to sub containers? 有谁知道另一个允许创建/上传到子容器的Rackspace库?

You are very close! 你很亲密! The trick is to put a URL path separator, / , in the object name, rather than in the container name. 技巧是在对象名称而不是容器名称中放置URL路径分隔符/ This is how the OpenStack ObjectStorage API works, and is not specific to the .NET SDK or Rackspace. 这就是OpenStack ObjectStorage API的工作方式,并不特定于.NET SDK或Rackspace。

In the example console application below, I create a container, images , and then add a file to a subdirectory in that container by naming it thumbnails/logo.png . 在下面的示例控制台应用程序中,我创建一个images容器,然后通过将文件命名为thumbnails/logo.png将文件添加到该容器的子目录中。 The resulting public URL for the file is printed out, and is essentially the container's public URL + the file name or http://abc123.r27.cf1.rackcdn.com/thumbnails/logo.png . 打印出的文件的公共URL就是容器的公共URL +文件名或http://abc123.r27.cf1.rackcdn.com/thumbnails/logo.png The container URL will be unique to each container and user. 容器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.

相关问题 使用Rackspace上传文件 - File Upload with Rackspace Rackspace CloudFiles C#API:如何在根“文件夹”中列出文件,以及如何在“文件夹”中列出(子)文件夹? - Rackspace CloudFiles C# API: How to list files on root 'folder', and how to list (sub)folders within a 'folder'? 我们如何使用C#中的API将文件上传到机架云容器中 - How we can Upload files into rackspace cloud container with API in C# 如何使用openstack.net在rackspace CloudFiles容器中创建Content-Type“application / directory”对象? - How to create an object with Content-Type “application/directory” inside a rackspace CloudFiles Container with openstack.net? 上传文件以创建目录ASP.Net Core Mac OS不会创建子文件夹 - File upload to create directory ASP.Net core mac os doesn't create sub folder 如何创建无限嵌套的子菜单? - How to create infinite nested sub menus? 如何创建范围有限的子枚举器? - How to create sub-enumerator with limited scope? 如何在目录中创建子目录 - how to create a sub directory inside a directory 在C#中设置目录和子容器的所有者 - Set Owner of Directory and Sub Containers in C# 拒绝访问路径或如何为机架空间站点添加模拟? - Access to the path is denied or How Do I Add Impersonation for a rackspace site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM