简体   繁体   中英

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. I got the basic code down, got the API key, got a username, the basic stuff. 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 .

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. 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. 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.

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 .

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.

The following doc page describes the method in detail and includes a complete C# example.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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