将大量文件上传到azure文件存储的最佳方法是什么?

时间:2017-10-03 02:38:38

标签: azure azure-storage-files azure-node-sdk

我希望文件存储特别不是blob存储(我认为)。这是我的azure函数的代码,我在node_modules文件夹中只有很多东西。

我想要做的是上传整个应用程序的拉链,然后上传并将azure解压缩到给定的文件夹中。这可能吗?

现在我基本上遍历所有文件并调用:

var fileStream = new stream.Readable();
fileStream.push(myFileBuffer);
fileStream.push(null);

fileService.createFileFromStream('taskshare', 'taskdirectory', 'taskfile', fileStream, myFileBuffer.length, function(error, result, response) {
  if (!error) {
    // file uploaded
  }
});

这个工作太慢了。所以我想知道是否有更快的方式来上传一堆文件以供在应用程序中使用。

1 个答案:

答案 0 :(得分:0)

  

这个工作太慢了。所以我想知道是否有更快的方式来上传一堆文件以供在应用程序中使用。

如果可以接受Microsoft Azure存储数据移动库,请尝试使用它。 Microsoft Azure Storage Data Movement Library专为高性能设计,用于上传,下载和复制Azure存储Blob和文件。该库基于为AzCopy提供支持的核心数据移动框架。

我们也可以从github document获取演示代码。

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");

// 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();
相关问题