简体   繁体   English

Rackspace云文件在容器C#中获取对象

[英]Rackspace Cloud Files Get Objects In Container C#

I have been looking at the documentation, testing examples and getting familiar with the Rackspace Cloud Files API. 我一直在查看文档,测试示例并熟悉Rackspace Cloud Files API。 I got the basic code down, got the API key, got a username, the basic stuff. 我记下了基本代码,API密钥,用户名和基本内容。 Now one thing confuses me, this problem is something that appears to be not well documented. 现在有一件事使我感到困惑,这个问题似乎没有得到很好的记录。

So what I am trying to do is to get all the objects, including folders and files in a container. 所以我想做的就是获取所有对象,包括容器中的文件夹和文件。 I have tried this example: 我试过这个例子:

IEnumerable<ContainerObject> containerObjects = cloudFilesProvider.ListObjects("storage",null,null,null,null,null,false,ci);

foreach(ContainerObject containerObject in containerObjects)
{
    MessageBox.Show(containerObject.ToString());
}

This doesn't return the result I am looking for, it seems to not return anything. 这不会返回我想要的结果,似乎什么也不会返回。

I am using OpenStack provided by running this in the NuGet console: Install-Package Rackspace . 我正在通过在NuGet控制台中运行此命令提供的OpenStack: Install-Package Rackspace

I am trying to create a file backup program for me and my family. 我正在尝试为我和我的家人创建文件备份程序。

A common problem is not specifying the region. 一个常见的问题是没有指定区域。 When your Rackspace cloud account's default region is not the same region as where your container lives, then you must specify region, otherwise you won't see any results listed. 如果您的Rackspace云帐户的默认区域与容器所在的区域不同,则必须指定区域,否则将不会列出任何结果。 Which is quite misleading... 这是相当误导的...

Here is a sample console application which prints the contents of all your containers (and their objects) in a particular region. 这是一个示例控制台应用程序,它在特定区域中打印所有容器(及其对象)的内容。 Change "DFW" to the name of the region where your container lives. 将“ DFW”更改为您的容器所在区域的名称。 If you aren't sure which region has your container, log into the Rackspace cloud control panel and go to "Storage > Files" and note the region drop down at the top right. 如果不确定容器所在的区域,请登录Rackspace云控制面板并转到“存储>文件”,然后注意该区域在右上角下拉。

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

namespace ListCloudFiles
{
    class Program
    {
        static void Main()
        {
            var region = "DFW";
            var identity = new CloudIdentity
            {
                Username = "username",
                APIKey = "apikey"
            };

            var cloudFilesProvider = new CloudFilesProvider(identity);

            foreach (Container container in cloudFilesProvider.ListContainers(region: region))
            {
                Console.WriteLine(container.Name);

                foreach (ContainerObject obj in cloudFilesProvider.ListObjects(container.Name, region: region))
                {
                    Console.WriteLine(" * " + obj.Name);
                }
            }
            Console.ReadLine();
        }
    }
}

If you are using the Openstack.NET API the reference documentation indicates that CloudFilesProvider has a method called ListObjects . 如果您使用的是Openstack.NET API,则参考文档会指出CloudFilesProvider有一个名为ListObjects的方法。

The docs say that this method: 文档说这种方法:

Lists the objects in a container 列出容器中的对象

The method returns IEnumerable<ContainerObject> and a quick glance at the parameter list looks to me like you can pass just a container name in the first parameter and null for the rest -- I'll leave it to you to figure out your use-case needs. 该方法返回IEnumerable<ContainerObject> ,快速浏览一下参数列表对我来说就像您可以在第一个参数中只传递一个容器名称,而在其余参数中传递null一样-我会留给您找出用途-案例需求。

The following doc page describes the method in detail and includes a complete C# example. 以下文档页面详细描述了该方法,并包括完整的C#示例。

http://www.openstacknetsdk.org/docs/html/M_net_openstack_Providers_Rackspace_CloudFilesProvider_ListObjects.htm http://www.openstacknetsdk.org/docs/html/M_net_openstack_Providers_Rackspace_CloudFilesProvider_ListObjects.htm

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

相关问题 我们如何使用C#中的API将文件上传到机架云容器中 - How we can Upload files into rackspace cloud container with API in C# 在C#中将文件上传到Rackspace Cloud Files时跟踪进度 - Track progress when uploading file to Rackspace Cloud Files in C# Rackspace云文件c#,添加文件到目录 - Rackspace cloud file c#, adding files to directory 如何使用C#将附件对象保存到RackSpace Cloud? - How To Save Attachments object to RackSpace Cloud using C#? 使用C#API从启用Rackspace CloudFiles CDN的容器中检索图像 - Retrieve Image From Rackspace CloudFiles CDN-Enabled Container with C# API 仅获取Google Cloud Storage C#中“文件夹”内的对象 - Get only objects inside “folder” in Google Cloud Storage C# RackSpace CloudFiles如何使用异步或队列使用C#发送文件 - RackSpace CloudFiles how to use Asynchronous or Queue to send files using C# Rackspace CloudFiles C#API:如何在根“文件夹”中列出文件,以及如何在“文件夹”中列出(子)文件夹? - Rackspace CloudFiles C# API: How to list files on root 'folder', and how to list (sub)folders within a 'folder'? CloudFiles-Rackspace连接错误C# - CloudFiles - Rackspace connection error c# 如何使用 c# 获取 Azure 容器虚拟文件夹中的文件 - How to get the files in an Azure container virtual folder using c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM