使用共享访问签名的Azure ZIP多个文件并从流中下载

问题描述:

我正在使用 DotNetZip 用于将Blob压缩(或尝试至少).

I'm using Shared Access Signatures for downloading blobs from my blobstorage and DotNetZip for zipping the blobs, (or trying atleast).

   var images = _fileService.GetImages(companyID, model.ImageIDs).ToList();

        if (images != null && images.Count > 0)
        {
            DateTime currentTime = TimeZoneExtensions.GetCurrentDate();

            using (ZipFile zip = new ZipFile())
            {
                MemoryStream output = new MemoryStream();

                foreach (var image in images)
                {
                    if (image.ImageLinks != null)
                    {
                        //ImageLinks contains SAS uri for each image format..
                        List<ImageLinkModel> imageLinks = image.ImageLinks.Where(m => m.FormatID == model.FormatID).ToList();

                        if (imageLinks != null && imageLinks.Count > 0)
                        {
                            foreach (var imageLink in imageLinks)
                            {
                                if (String.IsNullOrEmpty(imageLink.DownloadURL) || imageLink.DateExpiresDownloadURL < currentTime)
                                {
                                    int hours = 1;

                                    imageLink.DateExpiresDownloadURL = currentTime.AddHours(hours);

                                    //Create new shared access signature
                                    imageLink.DownloadURL = _fileService.GetDownloadImageURL(imageLink.BlobName, image.ImageName, hours);

                                    //Update imagelink
                                    _fileService.UpdateImageLink(companyID, imageLink);

                                    //Exception here
                                    zip.AddDirectory(imageLink.DownloadURL);
                                }
                                else
                                {

                                    //Use existing SAS download url

                                    Exception here
                                    zip.AddDirectory(imageLink.DownloadURL);
                                }
                            }

                            zip.Save(output);
                        }
                    }
                }

                return File(output, "application/zip", "sample.zip");
            }
        }

这是我到目前为止提出的.

This is what I have come up with so far.

运行此方法并将文件添加到zip时,出现异常: System.ArgumentException不支持URI格式.我认为您只能将本地路径添加到zip中,这很有意义,所以现在我没有主意了.

When running this method and adding a file to the zip I get the exception: System.ArgumentException URI format not supported. I assume you can only add local path to the zip which makes sense, so now I'm out of ideas.

这是我的SAS URL之一:

This is one of my SAS URLs:

URL没什么问题,(我无需压缩即可下载).

It's nothing wrong with the URL, (I can download without zipping).

我要在这里做不可能的事吗?我是否被迫按的常规方式下载Blob?然后将它们拉上拉链?

Am I trying to do the impossible here? Am I forced to download the blobs the normal way like this and after that zip them?

谢谢

Azure认为blob存储只是其中包含一些位和字节的边界.它没有文件类型的概念,也没有处理程序对其进行任何处理的概念.(HTTP也不是)

As far as Azure sees blob storage is just a boundary with some bits and bytes in it. It has no concept of file types, or handlers to do anything with them. (and neither does HTTP)

您希望在不存在的存储中获得智能.唯一可以使用URI的方法就是下载

You are hoping for intelligence in the storage that doesn't exist. The only thing you can do with the URI is to download it,

是的,您需要下载它,然后压缩它,然后将其发送到任何地方.

So yes you need to download it, then zip it then send it wherever its going.