簡體   English   中英

Rackspace雲文件c#,添加文件到目錄

[英]Rackspace cloud file c#, adding files to directory

使用機架空間雲文件將文件添加到特定目錄,c# 綁定 api 更具體參考: https://github.com/rackspace/csharp-cloudfiles

出於某種奇怪的原因,執行以下操作:

    public static void UploadFile(CSImageDTO file)
    {
        var connection = new Connection(UserCredentials);
        var containerItemList = connection.GetContainerItemList(ContainerName);

        if (!containerItemList.Contains(file.Filename))
            connection.PutStorageItem(ContainerName, file.File, Path.Combine(MyPath, Path.GetFileName(file.Filename)));
        else
            throw new NotSupportedException("we dont know what to do now...");
    }

假設 MyPath = "Funky";

這會添加如下文件:

  • 時髦/Image1.jpg
  • 時髦/Image5.png
  • ...

我可以使用Path.GetFileName(filepath)獲取文件路徑並將其返回到視圖,但我想知道我的文件沒有存儲在“Funky”目錄下,而是實際文件名稱為"Funky/Image1.png" 或者它使用我的代碼出現:

 public static IEnumerable<string> GetFiles()
        {
            var connection = new Connection(UserCredentials);

            var parameters = new Dictionary<GetItemListParameters, string>();
            //parameters.Add(GetItemListParameters.Path, MyPath);

            var containerItemList = connection.GetContainerItemList(ContainerName, parameters)
                .Where(x => Path.HasExtension(x));
            //.Select(x => Path.GetFileName(x));

            return containerItemList;
        }

另請注意:我必須使用此過濾器來確保我不會找回文件夾...

.Where(x => Path.HasExtension(x));

因為它是一個平面文件系統...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM