簡體   English   中英

在C#中將文件上傳到Rackspace Cloud Files時跟蹤進度

[英]Track progress when uploading file to Rackspace Cloud Files in C#

我正在使用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);

看起來好像沒有內置的,沒有,但是您可能可以添加自己的。

一種替代方法是測量輸入。 如果您查看源代碼,您會發現WriteFromFile實際上只是

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

因此,您可以將傳遞給Write的流包裝在另一個測量總讀取字節進度的流類中(如果搜索,周圍會有一些,或者編寫自己很容易)。 如果您確實想從他們的代碼中添加進度通知,則需要將其添加到包裝的OpenStack Client對象中,但這也不難。

暫無
暫無

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

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