2012-05-03 55 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

謝謝,我會給它一個。 –