2012-05-03 56 views
1

我使用https://github.com/rackspace/csharp-cloudfiles创建了一个命令行工具来将文件上传到Rackspace Cloud文件。在C#中将文件上传到Rackspace Cloud文件时跟踪进度#

事情是,我不知道如何跟踪上传进度(似乎没有任何事件或事情)。

下面的代码:

// 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); 

回答

1

这里看起来并不像有一个内置的,没有,但你很可能添加您自己的。

另一种方法是测量输入;如果你看一下the source你会看到WriteFromFile实际上只是

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

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

+0

谢谢,我会给它一个。 –