在Azure Blob存储中对大型拉链流的效率且安全的处理

问题描述 投票:0回答:1
我需要从浏览器网络上载邮递到后端。该流的大小可以达到数百个兆字节。当前的方法涉及将流到隔离的存储进行扫描,并且只有在干净时,它才会以常规流量进行。由于流只能读一次,我考虑了两种方法:

  1. 复制的记忆中的流:由于可能会出现高内存使用量和DOS攻击的风险,尤其是在大文件中,这不是理想的选择。

    上传后,请从隔离存储中读取:这涉及将流写入隔离存储,然后从那里读取它,以避免将其保存在内存中。 但是,我担心的是,即使我写入Blob存储,然后从中读取它,读取仍然涉及内存使用情况。另外,它不是表演者。

  2. 在最大程度地减少内存使用量并确保安全性的同时,使用了更好的方法来克服此问题?

在最大程度地减少内存使用量并确保安全性的同时,使用了更好的方法来克服此问题?

memory stream zip blob azure-storage
1个回答
0
投票
我同意马克·阿德尔(Mark Adle)和安德鲁(Andrew)的评论,使用
ZipFlow

方法与a

SAS token
一起上传直接上传到Azure Blob存储中可以是一种有效的解决方案,可以在从浏览器流中传输文件时最大程度地减少内存使用情况。 您可以使用以下代码创建Azure存储帐户

SAS

代币。
代码:

public static string CreateAccountSasToken(string accountName, string accountKey) { var sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey); // Create Account SAS AccountSasBuilder sasBuilder = new AccountSasBuilder { ExpiresOn = DateTimeOffset.UtcNow.AddHours(1), // Set expiration time Services = AccountSasServices.Queues, // Enable queue service ResourceTypes = AccountSasResourceTypes.Service | AccountSasResourceTypes.Container | AccountSasResourceTypes.Object, }; sasBuilder.SetPermissions(AccountSasPermissions.Add | AccountSasPermissions.Create | AccountSasPermissions.Read | AccountSasPermissions.Write); string sasToken = sasBuilder.ToSasQueryParameters(sharedKeyCredential).ToString(); return sasToken; }

现在您可以使用saS令牌使用

JavaScript

将文件直接上传到Azure Blob存储中。 上载后,您可以使用

Blob Trigger Azure Function
自动扫描文件。这使您可以在Azure Blob存储中使用该文件后立即处理该文件。
函数可以将文件读为流,然后应用

ZipFlow

方法来扫描文件,而无需将其完全加载到内存中。

    参考:
  • 
    
  • 通过共享访问签名(SAS)的数据限制访问数据 - Azure Storage |微软学习
    
    
QuickStart:Azure Blob存储库V12 -JS浏览器-Azure Storage |微软学习

Azure函数的node.js开发人员参考|微软学习

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.