【问题标题】:Openstackdotnet SDK Object Storage Object VersioningOpenstackdotnet SDK 对象存储对象版本控制
【发布时间】:2015-12-03 09:53:00
【问题描述】:

我正在使用OpenStack SDK .NET 开发云备份客户端。在我的previous question 中,我遇到了身份识别问题,并且完美解决了。现在我几乎测试了我需要的所有功能,但有一件事似乎无法正常工作。 我需要在对象存储 swift 中创建对象版本控制功能。我在 Openstack 官方文档中读到我需要在 Rest 中添加一个标头:

X-Versions-Location: myversionlocation

在我的库中,我修改了创建容器的方法:

public void CreateContainer(string _containerName)
{
    filesProvider.CreateContainer(_containerName, null, null, false, null);
}

到:

public void CreateContainer(string _containerName)
{
    Dictionary<string, string> versioningHeader = new Dictionary<string, string>();
    versioningHeader.Add("X-Versions-Location", "versions");
    filesProvider.CreateContainer(_containerName, versioningHeader, null, false, null);
}

在容器中上传文件时没有问题,但是当我第二次上传时,我的应用程序在此行中抛出了 ResponseException: {"Unexpected HTTP error: PreconditionFailed"}:

public void UploadFile(string _containerName, string _fileName, ThrottledStream _stream)
{
    filesProvider.CreateObject(_containerName, _stream, _fileName, null, 4096, null, "RegionOne");
}

这是创建启用版本控制的容器的正确方法吗?

【问题讨论】:

    标签: c# .net cloud storage openstack


    【解决方案1】:

    基于该错误,您是否在创建对象时发送了“if-none-match”标头?当设置了该标头,并且您尝试上传容器中已存在的文件时,将引发该错误。我不相信您可以将该标头与版本控制一起使用,因为检查是基于名称,而不是正在上传的文件哈希。只是一个猜测。 :-)

    下面是一个控制台应用程序,它在上传新版本之前两次上传文件,以证明这应该可以工作。

    using System;
    using System.Collections.Generic;
    using net.openstack.Core.Domain;
    using net.openstack.Core.Providers;
    using net.openstack.Providers.Rackspace;
    
    namespace CloudFilesVersioning
    {
        class Program
        {
            static void Main(string[] args)
            {
                var identityUrl = new Uri("{identity-url}");
                var identity = new CloudIdentityWithProject
                {
                    Username = "{user}",
                    ProjectName = "{project-name}",
                    Password = "{password}"
                };
                const string region = "RegionOne";
    
                var identityProvider = new OpenStackIdentityProvider(identityUrl, identity);
                var filesProvider = new CloudFilesProvider(null, identityProvider);
    
                // Create versions container
                const string versionContainerName = "mycontainer-versions";
                filesProvider.CreateContainer(versionContainerName, region: region);
    
                // Create main container
                const string containerName = "mycontainer";
                var headers = new Dictionary<string, string>
                {
                    {"X-Versions-Location", versionContainerName}
                };
                filesProvider.CreateContainer(containerName, headers, region);
    
                // Upload the initial file
                filesProvider.CreateObjectFromFile(containerName, @"C:\thing-v1.txt", "thing.txt", region: region);
    
                // Upload the same file again, this should not create a new version
                filesProvider.CreateObjectFromFile(containerName, @"C:\thing-v1.txt", "thing.txt", region: region);
    
                // Upload a new version of the file
                filesProvider.CreateObjectFromFile(containerName, @"C:\thing-v2.txt", "thing.txt", region: region);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-22
      • 2021-01-28
      • 2019-12-08
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 2017-03-22
      • 2015-11-24
      相关资源
      最近更新 更多