简体   繁体   English

无法更新 Azure 文件共享/Blob 中的 zip 文件

[英]unable to update zip file in Azure File Share/Blob

I am using Azure File shar e I want to create zip file only once but wants to update it multiple times (upload multiple files after once created).我正在使用Azure 文件共享我只想创建一次 zip 文件,但想多次更新它(创建后上传多个文件)。 is it possible to create.zip file only once and add more files in it later without **overriding **existing files in zip.?是否可以只创建一次.zip 文件并在以后添加更多文件而不**覆盖**zip 中的现有文件。? when i tried to add more files in.zip it overrides existing files in zip with new file.当我尝试在 .zip 中添加更多文件时,它会用新文件覆盖 zip 中的现有文件。

private static async Task OpenZipFile()
    {
        try
        {



            using (var zipFileStream = await OpenZipFileStream())
            {
                using (var zipFileOutputStream = CreateZipOutputStream(zipFileStream))
                {
                    var level = 0;
                    zipFileOutputStream.SetLevel(level);


                    BlobClient blob = new BlobClient(new Uri(String.Format("https://{0}.blob.core.windows.net/{1}", "rtsatestdata", "comm/2/10029.txt")), _currentTenantTokenCredential);

                    var zipEntry = new ZipEntry("newtestdata")
                    {
                        Size = 1170
                    };
                    zipFileOutputStream.PutNextEntry(zipEntry);

                    blob.DownloadToAsync(zipFileOutputStream).Wait();
                    zipFileOutputStream.CloseEntry();
                }
            }
        }
        catch (TaskCanceledException)
        {

            throw;
        }
    }


private static async Task<Stream> OpenZipFileStream()
    {

BlobContainerClient mainContainer = _blobServiceClient.GetBlobContainerClient("comm");

        var blobItems = mainContainer.GetBlobs(BlobTraits.Metadata, BlobStates.None);

        foreach (var item in blobItems)
        {
            if (item.Name == "testdata.zip")
            {
                BlobClient blob = new BlobClient(new Uri(String.Format("https://{0}.blob.core.windows.net/{1}", "rtsatestdata", "comm/testdata.zip")), _currentTenantTokenCredential);

               return await blob.OpenWriteAsync(true
                    , options: new BlobOpenWriteOptions
                    {
                        HttpHeaders = new BlobHttpHeaders
                        {
                            ContentType = "application/zip"
                        }
                    }
                );

            }
        }
}

private static ZipOutputStream CreateZipOutputStream(Stream zipFileStream)
    {
        return new ZipOutputStream(zipFileStream)
        {
            IsStreamOwner = false,
        };
    }

This is not possible in Azure storage.这在 Azure 存储中是不可能的。 The workaround would be to download the zip, unzip it, add more files, re-zip it, and re-upload to storage.解决方法是下载 zip,解压缩,添加更多文件,重新压缩,然后重新上传到存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM