如何读取要从一个Blob流式传输并上传到另一个Blob的文件?我的要求是将文件从一个blob复制到另一个具有不同文件名的blob?在C#中C#从一个blob副本文件到另一个blob的Azure存储
0
A
回答
0
复制文件的最简单方法之一是使用AzCopy实用程序。
6
实现它的最简单方法是使用"Azure Storage Data Movement Library"(你可以通过nuget包得到它)。
这是一个简单的样本,使传输:
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.DataMovement;
using System;
namespace BlobClient
{
class Program
{
static void Main(string[] args)
{
const string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=juanktest;AccountKey=loHQwke4lSEu1p2W3gg==";
const string container1 = "juankcontainer";
const string sourceBlobName = "test.txt";
const string destBlobName = "newTest.txt";
//Setup Account, blobclient and blobs
CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference(container1);
blobContainer.CreateIfNotExists();
CloudBlockBlob sourceBlob = blobContainer.GetBlockBlobReference(sourceBlobName);
CloudBlockBlob destinationBlob = blobContainer.GetBlockBlobReference(destBlobName);
//Setup data transfer
TransferContext context = new TransferContext();
Progress<TransferProgress> progress = new Progress<TransferProgress>(
(transferProgress) => {
Console.WriteLine("Bytes uploaded: {0}", transferProgress.BytesTransferred);
});
context.ProgressHandler = progress;
// Start the transfer
try
{
TransferManager.CopyAsync(sourceBlob, destinationBlob,
false /* isServiceCopy */,
null /* options */, context);
}
catch (Exception e)
{
Console.WriteLine("The transfer is cancelled: {0}", e.Message);
}
Console.WriteLine("CloudBlob {0} is copied to {1} ====successfully====",
sourceBlob.Uri.ToString(),
destinationBlob.Uri.ToString());
Console.ReadLine();
}
}
}
注意,“Azure存储数据移动图书馆”是非常强大的,所以你可以跟踪传输进度,取消操作,甚至暂停它稍后恢复;)
相关问题
- 1. 如何使用PowerShell将文件从一个Blob存储容器移动到另一个Blob存储容器
- 2. 从本地存储上传所有文件到Azure Blob存储
- 3. Azure Blob存储列表Blob
- 4. Interupting从Azure的Blob存储
- 5. 将文件上传到Azure Blob存储
- 6. FileUpload文件到Azure Blob存储
- 7. Azure的Blob存储
- 8. 如何从Azure启动任务中的blob存储获取副本文件?
- 9. 如何将Azure Blob文件复制到Azure本地存储
- 10. 消除另一个blob内的blob
- 11. C#MySQL Blob字段 - 无法将存储在blob中的zip文件复制到另一个表中
- 12. C#不从Azure blob存储中检索blob
- 13. Azure DocumentDB和Azure Blob存储
- 14. Azure blob存储文件路径限制
- 15. 在Azure的Blob存储
- 16. asp.net的Windows Azure Blob存储
- 17. Azure将文件从blob存储移动到同一存储帐户中的文件存储
- 18. 将Azure虚拟机本地文件夹备份到blob存储?
- 19. Azure的功能 - 调整存储在一个blob容器
- 20. 如何从网站图片上传文件到Azure Blob存储?
- 21. 直接从浏览器上传文件到Azure Blob存储?
- 22. 将文件从客户端上传到Azure Blob存储| MVC
- 23. Azure blob存储拆分blob并存储在云文件共享上
- 24. Azure存储Blob -com.microsoft.azure.storage.core.Utility错误
- 25. Azure blob存储;派生列
- 26. ImageResizer与Azure Blob存储Azurewebsites
- 27. CNAME与Azure Blob存储
- 28. Azure blob存储和CDN
- 29. 流星和Azure Blob存储
- 30. 访问存储在Windows Azure BLOB上的文本文件
你测试了代码吗? – JuanK