将Big ZipArchive-MemoryStream上载到Azure [英] Upload Big ZipArchive-MemoryStream to Azure

查看:84
本文介绍了将Big ZipArchive-MemoryStream上载到Azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR :是否有可能在压缩时将大的MemoryStream作为块快速上传到Azure?

TL;DR: Is it possible to upload a big MemoryStream to Azure as chunks on the fly while zipping?

我有保存到MemoryStream中的文件,我将这些文件添加到另一个MemoryStream中的ZipArchive中.
我想使用

I have files which get saved into a MemoryStream, I add these files to a ZipArchive in another MemoryStream.
This MemoryStream I want to upload to an Azure-BlockBlob-Storage using

blockBlob.UploadFromStream(zipMemoryStream);

到目前为止一切都很好.
现在的问题是,Zip存档可能会变得更大,然后是 8GB ,这是MemoryStream的问题.

So far so good.
The Problem now is, that the Zip-Archive might get bigger then 8GB which is a problem with the MemoryStream.

是否可以将内存流中的部分作为块上传到蔚蓝,然后从流中删除这些字节?

Is it possible to upload parts from the memory-stream as chunks to azure, and remove these bytes from the Stream?

还是有更好的方法来处理zipArchive和azure?

Or is there a better approach to deal with zipArchive and azure?

要进行压缩,我在包System.IO.Compression

最好的问候,
Flo

Best Regards,
Flo

推荐答案

可能不是您要找的东西,但是您是否尝试执行以下操作:

It may be not exactly what you are looking for, but did you try to do something like this:

var blob = container.GetBlockBlobReference("zipped.zip");
using (var stream = new ZipArchive(blob.OpenWrite(), ZipArchiveMode.Create))
{
    var entry = stream.CreateEntry("entry1");
    using (var es = entry.Open())
    {
        // Fill entry with data
    }

    // Other code
}

当您调用CloudBlockBlobOpenWrite时,它会创建一个CloudBlobStream实例,该实例的工作方式与MemoryStream不同.就我记得CloudBlobStream不会将old块保存到内存中而言,CloudBlobStream以4MB块的形式将数据发送到Azure存储服务.

When you call OpenWrite of CloudBlockBlob it creates an instance of CloudBlobStream that works in a different way than MemoryStream. CloudBlobStream sends data to Azure Storage Service in 4MB chunks, as far as I remember it doesn't save old chunks into the memory.

这篇关于将Big ZipArchive-MemoryStream上载到Azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆