【问题标题】:zip file Error URI formats are not supportedzip 文件错误 URI 格式不受支持
【发布时间】:2013-09-28 21:32:01
【问题描述】:

我在这里尝试使用 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");
            }

我查看了类似问题here 的答案。我也遵循相同的 url 格式,那么为什么会出现此错误。请帮我解决此错误

我将上面的代码修改如下,压缩文件正在创建但已损坏。 在我的 blob 容器“myfiles”中,我想创建一个名为“mymusic.zip”的 zip 文件,方法是读取 myMusic 文件夹中的所有文件和文件夹,同时在 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 文件损坏了?

【问题讨论】:

    标签: c# zip azure-blob-storage


    【解决方案1】:

    This site 看起来既解决了问题又解决了问题。

    奶酪 - 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().

    然后他继续编写示例解决方案

    【讨论】:

    • 提供的示例使用接受流的 ZipFile.AddEntry() 方法,但在我的情况下,我需要压缩特定目录
    【解决方案2】:

    我不熟悉 dotnetzip,但我想我知道你的问题。

    访问服务器时使用服务器路径,而不是 URI(网址)。操作系统不知道http://your.website实际上是其c:\\web\website\somedirectory的一部分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2021-10-24
      • 2012-03-26
      相关资源
      最近更新 更多