将ZipArchive条目提取到Blob存储 [英] Extract ZipArchive entry to blob storage
本文介绍了将ZipArchive条目提取到Blob存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用普通的Windows文件系统, ExtractToFile
方法就足够了:
Using the normal Windows file system, the ExtractToFile
method would be sufficient:
using (ZipArchive archive = new ZipArchive(uploadedFile.InputStream, ZipArchiveMode.Read, true))
{
foreach (var entry in archive.Entries.Where(x => x.Length > 0))
{
entry.ExtractToFile(Path.Combine(location, entry.Name));
}
}
现在我们正在使用Azure,这显然需要随着使用blob存储而改变.
Now that we are using Azure, this obviously needs to change as we are using blob storage.
这怎么办?
推荐答案
ZipArchiveEntry
类具有
ZipArchiveEntry
class has an Open
method which returns a stream. What you could do is create a blob using that stream.
static void ZipArchiveTest()
{
storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobContainer container = storageAccount.CreateCloudBlobClient().GetContainerReference("temp");
container.CreateIfNotExists();
var zipFile = @"D:\node\test2.zip";
using (FileStream fs = new FileStream(zipFile, FileMode.Open))
{
using (ZipArchive archive = new ZipArchive(fs))
{
var entries = archive.Entries;
foreach (var entry in entries)
{
CloudBlockBlob blob = container.GetBlockBlobReference(entry.FullName);
using (var stream = entry.Open())
{
blob.UploadFromStream(stream);
}
}
}
}
}
这篇关于将ZipArchive条目提取到Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文