簡體   English   中英

zip文件不支持錯誤URI格式

[英]zip file Error URI formats are not supported

在這里,我嘗試使用dotnetzip壓縮目錄的內容,並且收到此錯誤消息不支持URI格式。
這是我用來執行此操作的代碼。

string strDirectoryName="http://zyx.blob.core.windows.net/myfiles/mymusic"
       using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(strDirectoryName);
                zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
                zip.Save("zipFileToCreate");
            }

在這里調查類似問題的答案。我也遵循相同的url格式,然后為什么會收到此錯誤。請幫助我解決此錯誤

我修改了上面的代碼,如下所示,並且zip文件已創建但已損壞。 在我的Blob容器“ myfiles”中,我想通過讀取myMusic文件夾中的所有文件和文件夾,同時在zip文件中保留相同的文件夾結構,來創建一個名為“ mymusic.zip”的zip文件。以下代碼創建了該zip文件,但是zip文件已損壞。是否有解決此問題的建議?

string ofurl = @"http://myxyzstorage.blob.core.windows.net/myfiles/mymusic";
            string ofBlob = @"http://myxyz.blob.core.windows.net/myfiles";
          dBlob = new CloudBlob(blobClient.GetBlobReference(ofBlob));

            using (var zipFile = new ZipFile())
            {
                byte[] fileBytes = dBlob.DownloadByteArray();
                using (var fileStream = new MemoryStream(fileBytes))
                {
                    fileStream.Seek(0, SeekOrigin.Begin);
                    zipFile.AddEntry(ofurl+".zip", fileBytes);
                }
                var sas = offlineContainer.GetSharedAccessSignature(new SharedAccessPolicy()
                {
                    Permissions = SharedAccessPermissions.Write,
                 // SharedAccessExpiryTime = DateTime.UtcNow.AddSeconds(this.timeOutSeconds)
                });

                using (var zipStream = new MemoryStream())
                {
                    zipFile.Save(zipStream);
                    zipStream.Seek(0, SeekOrigin.Begin);
                    var blobRef = ofContainer.GetBlobReference(ofurl);
                    blobRef.UploadFromStream(zipStream);
                }

            }

這里上面有我的代碼,為什么我的zip文件已損壞?

該站點看起來既解決了問題又解決了問題。

Cheeso- DotNetZip can read from filesystems. It cannot read from http sources. An easy way to do what you want is to send a GET request to the HTTP resource, and then pass the ResponseStream to the call to AddFile(). DotNetZip can read from filesystems. It cannot read from http sources. An easy way to do what you want is to send a GET request to the HTTP resource, and then pass the ResponseStream to the call to AddFile().

然后,他繼續編寫示例解決方案

我不熟悉dotnetzip,但我想我知道您的問題。

訪問服務器項目時,請使用服務器路徑,而不要使用URI(網址)。 操作系統不知道http://your.website實際上是其c:\\\\web\\website\\somedirectory

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM