你可能指的是使用相同的框架庫代碼:
首先,包括你所需要的課程,我們在這裏包括存儲客戶端庫,存儲數據的移動圖書館和.NET線程,因爲數據移動圖書館提供任務異步接口傳輸存儲對象:
using System;
using System.Threading;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.DataMovement;
現在使用的存儲客戶端的lib提供設置存儲上下文(找到如何從.NET使用Blob存儲更多細節)接口:
string storageConnectionString = "myStorageConnectionString";
CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("mycontainer");
blobContainer.CreateIfNotExists();
string sourcePath = "path\\to\\test.txt";
CloudBlockBlob destBlob = blobContainer.GetBlockBlobReference("myblob");
一旦你設置存儲BLOB情況下,你就可以開始使用WindowsAzure.Storage.DataMovement.TransferManager上傳blob和跟蹤上傳進度,
// Setup the number of the concurrent operations
TransferManager.Configurations.ParallelOperations = 64;
// Setup the transfer context and track the upoload progress
SingleTransferContext context = new SingleTransferContext();
context.ProgressHandler = new Progress<TransferStatus>((progress) =>
{
Console.WriteLine("Bytes uploaded: {0}", progress.BytesTransferred);
});
// Upload a local blob
var task = TransferManager.UploadAsync(
sourcePath, destBlob, null, context, CancellationToken.None);
task.Wait();
瞭解更多:
Storage Client Library Reference for .NET - MSDN
如果要複製一個blob到一個文件或文件到一個blob,則必須使用一個共享訪問簽名(SAS)來驗證源對象,即使您在同一個存儲帳戶中進行復制。
我在最後一行得到一個404沒有找到的異常,但是這個文件肯定存在。 – Iason