你可能指的是使用相同的框架库代码:
首先,包括你所需要的课程,我们在这里包括存储客户端库,存储数据的移动图书馆和.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