2012-04-02 111 views
0

我上傳一個視頻在我的網站上,由客戶端使用簡單的上傳程序,然後上傳到代碼隱藏使用blob.UploadByteArray(),上傳到azure blob我想跟蹤上傳在那一刻總共上傳了多少字節的進度?有沒有任何API或解決方法?不要第三方上傳或blob推等。在此先感謝!跟蹤上傳進度,同時上傳文件到azure blob

回答

0

我還沒有找到API來跟蹤進度。我已經實現了進度條的一種方式是將blob作爲較小的塊上傳到Azure存儲。當每個塊成功上傳時,您可以根據塊的數量改變進度條。

0

我讀到CorneM提到的博客文章,但我不是在執行太熱衷..

相反,我的子類的FileStream,以便它引發的事件,每隔一段時間,它正在讀取,並提供我的子類filestream添加到SDK中Azure存儲客戶端上的UploadFromStream方法。乾淨多了,恕我直言

public delegate void PositionChanged(long position); 

public class ProgressTrackingFileStream: FileStream 
{ 
    public int AnnounceEveryBytes { get; set; } 
    private long _lastPosition = 0; 


    public event PositionChanged StreamPositionUpdated; 

    // implementing other methods that the storage client may call, like ReadByte or Begin/EndRead is left as an exercise for the reader 

    public override int Read(byte[] buffer, int offset, int count) 
    { 
     int i = base.Read(buffer, offset, count); 

     MaybeAnnounce(); 

     return i; 
    } 

    private void MaybeAnnounce() 
    { 
     if (StreamPositionUpdated != null && (base.Position - _lastPosition) > AnnounceEveryBytes) 
     { 
      _lastPosition = base.Position; 
      StreamPositionUpdated(_lastPosition); 
     } 
    } 

    public ProgressTrackingFileStream(string path, FileMode fileMode) : base(path, fileMode) 
    { 
     AnnounceEveryBytes = 32768; 
    } 

} 

然後使用它像這樣(_container是我的Azure存儲容器,文件是我的本地文件一個FileInfo):

 CloudBlockBlob blockBlob = _container.GetBlockBlobReference(blobPath); 

     using (ProgressTrackingFileStream ptfs = new ProgressTrackingFileStream(file.FullName, FileMode.Open)) 
     { 
      ptfs.StreamPositionUpdated += ptfs_StreamPositionUpdated; 

      blockBlob.UploadFromStream(ptfs); 
     } 
+0

這是不準確的,你只是跟蹤閱讀將文件存儲到內存中,而不會將其上傳到Azure,這需要花費更長的時間。我正在尋找一個解決方案,我認爲準確的方法應該是在塊級別左右。 – Hossam 2014-01-05 14:00:36