【问题标题】:What is the best way to upload a large number of files to azure file storage?将大量文件上传到 azure 文件存储的最佳方法是什么?
【发布时间】:2017-10-03 02:38:38
【问题描述】:

我特别想要文件存储而不是 blob 存储(我认为)。这是我的 azure 函数的代码,我的 node_modules 文件夹中只有一堆东西。

我想做的是上传整个应用程序的 zip,然后上传它并在给定文件夹中将其解压缩。这可能吗?

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

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

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

【问题讨论】:

  • 如果您尝试同时上传文件会怎样?
  • 我改变了它来做到这一点,但它对于我的期望来说仍然太慢了。它从大约 30 分钟到 5 分钟。但似乎有一个kudu api 用于发送和解压缩 zip 文件。我还在努力解决,如果我能做到,我会在这里发布结果。

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


【解决方案1】:

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

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

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

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

【讨论】:

  • 我正在使用nodejs,所以我不能直接使用这个库,我正在尝试查看代码并查看它使用的是什么api。我也在使用 File 而不是 Blob。
猜你喜欢
  • 1970-01-01
  • 2016-08-18
  • 2020-07-10
  • 1970-01-01
  • 1970-01-01
  • 2017-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多