作者:时-_尚微视点 | 来源:互联网 | 2024-10-26 11:01
我正致力于利用AzureFunctions和System.IO.Compression库,将大量文件高效地压缩并存储到AzureBlob容器中。这种方法不仅提高了存储效率,还优化了数据管理流程。通过这种方式,可以显著减少存储成本,并提升数据访问速度。
我正在尝试使用azure函数通过System.IO.Compression将所有文件压缩到blob容器内。
我可以使用下面的CloudBlob代码列出容器内的所有文件
CloudStorageaccount storageaccount = CloudStorageaccount.Parse (storageConn);
CloudBlobClient blobClient = storageaccount.CreatecloudBlobClient();
CloudBlobContainer cOntainer= blobClient.getcontainerReference("");
BlobContinuationToken blobToken = null;
var blobs = await container.ListBlobsSegmentedAsync(blobToken);
var fileList = new List();
var blobpath1 = @"https:///test.zip";
foreach (var blbitem in blobs.Results)
{
if (blbitem is CloudBlockBlob)
{
var blobFileName = blbitem.Uri.Segments.Last().Replace("%20"," ");
var blobFilePath = blbitem.Uri.AbsolutePath.Replace(blbitem.Container.Uri.AbsolutePath + "/","").Replace("%20"," ");
var blobPath = blobFilePath.Replace("/" + blobFileName,"");
log.LogInformation("blob path : " + blbitem.Uri.ToString());
fileList.Add(blbitem.Uri.ToString());
string rootpath = @"D:\home\site\wwwroot\ZipandSendFile\temp\";
string path = rootpath + blobPath;
log.LogInformation("saving in " + path);
//Add to zip
/*
CloudBlobContainer cOntainer= cloudBlobClient.getcontainerReference("");
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
using (FileStream fs = new FileStream(rootpath,FileMode.Create))
{
blob. DownloadToStream(fs);
}
*/
}
}
获取blob中的每个文件详细信息之后,我试图将它们添加到zip存档中
使用下面的System.IO.Compression包
我尝试下载文件
public static void AddFilesToZip(string zipPath,string[] files,ILogger log)
{
if (files == null || files.Length == 0)
{
return;
}
log.LogInformation("Executing add files to zip");
log.LogInformation(zipPath);
using (var zipArchive = ZipFile.Open(zipPath,ZipArchiveMode.Update))
{
log.LogInformation("in Zip archive");
foreach (var file in files)
{
var fileInfo = new FileInfo(file);
log.LogInformation(fileInfo.FullName);
zipArchive.CreateEntryFromFile(fileInfo.FullName,fileInfo.Name);
}
}
}
但是我无法访问。有任何指针吗?
已通过登录kudo cmdshell和cd进入目录并更改文件属性来解决此问题
使用attrib + A 。