Reputation: 2433
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.
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.
This is one of my SAS URLs:
It's nothing wrong with the URL, (I can download without zipping).
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?
Thanks
Upvotes: 0
Views: 954
Reputation: 12228
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)
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.
Upvotes: 1