【问题标题】:Track progress when uploading file to Rackspace Cloud Files in C#在 C# 中将文件上传到 Rackspace Cloud Files 时跟踪进度
【发布时间】:2012-05-03 09:22:40
【问题描述】:

我正在使用https://github.com/rackspace/csharp-cloudfiles 构建一个命令行工具来将文件上传到 Rackspace Cloud Files。

问题是我不知道如何跟踪上传进度(似乎没有任何类型的事件或其他东西)。

代码如下:

// Create credentials, client and connection
var creds = new UserCredentials(username, apiKey);
CF_Client client = new CF_Client();
Connection conn = new CF_Connection(creds, client);
conn.Authenticate();

// Get container and upload file
var container = new CF_Container(conn, client, containerName);
var obj = new CF_Object(conn, container, client, remoteFileName);
obj.WriteFromFile(localFilePath);

【问题讨论】:

    标签: c# .net rackspace-cloud cloudfiles


    【解决方案1】:

    似乎没有内置的,不,但您可能会添加自己的。

    另一种方法是测量输入;如果您查看the source,您会发现 WriteFromFile 实际上只是

    Dictionary<string,string> headers = new Dictionary<string,string>();
    using(Stream stream = System.IO.File.OpenRead(localFilePath))
    {
        obj.Write(stream, headers);
    }
    

    所以您可以将传递给 Write 的流包装在另一个流类中,该流类测量总字节读取进度(如果您搜索,周围有一些,或者自己编写很容易)。如果您确实想从他们的代码中添加进度通知,则需要将其添加到已包装的 OpenStack Client object 中,但这也不应该太难。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 2023-03-31
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      相关资源
      最近更新 更多