• <bdo id='eYcox'></bdo><ul id='eYcox'></ul>
  • <small id='eYcox'></small><noframes id='eYcox'>

      <tfoot id='eYcox'></tfoot>
      <i id='eYcox'><tr id='eYcox'><dt id='eYcox'><q id='eYcox'><span id='eYcox'><b id='eYcox'><form id='eYcox'><ins id='eYcox'></ins><ul id='eYcox'></ul><sub id='eYcox'></sub></form><legend id='eYcox'></legend><bdo id='eYcox'><pre id='eYcox'><center id='eYcox'></center></pre></bdo></b><th id='eYcox'></th></span></q></dt></tr></i><div id='eYcox'><tfoot id='eYcox'></tfoot><dl id='eYcox'><fieldset id='eYcox'></fieldset></dl></div>

    1. <legend id='eYcox'><style id='eYcox'><dir id='eYcox'><q id='eYcox'></q></dir></style></legend>

        如何在 Blob 存储中创建文件夹

        how to create folder in blob storage(如何在 Blob 存储中创建文件夹)
          <tbody id='JLPPQ'></tbody>

        1. <tfoot id='JLPPQ'></tfoot>
          • <legend id='JLPPQ'><style id='JLPPQ'><dir id='JLPPQ'><q id='JLPPQ'></q></dir></style></legend>
            <i id='JLPPQ'><tr id='JLPPQ'><dt id='JLPPQ'><q id='JLPPQ'><span id='JLPPQ'><b id='JLPPQ'><form id='JLPPQ'><ins id='JLPPQ'></ins><ul id='JLPPQ'></ul><sub id='JLPPQ'></sub></form><legend id='JLPPQ'></legend><bdo id='JLPPQ'><pre id='JLPPQ'><center id='JLPPQ'></center></pre></bdo></b><th id='JLPPQ'></th></span></q></dt></tr></i><div id='JLPPQ'><tfoot id='JLPPQ'></tfoot><dl id='JLPPQ'><fieldset id='JLPPQ'></fieldset></dl></div>

                <small id='JLPPQ'></small><noframes id='JLPPQ'>

                  <bdo id='JLPPQ'></bdo><ul id='JLPPQ'></ul>
                  本文介绍了如何在 Blob 存储中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个文件,例如 Parent.zip,解压后会生成以下文件: child1.jpg , child2.txt, child3.pdf.

                  I have a file such as Parent.zip and when unzipped, it will yield these files: child1.jpg , child2.txt , child3.pdf.

                  当通过下面的函数运行Parent.zip时,文件被正确解压到:

                  When running Parent.zip through the function below, the files are correctly unzipped to:

                  some-container/child1.jpg
                  some-container/child2.txt
                  some-container/child3.pdf
                  

                  如何将文件解压缩到其父文件夹?所需的结果是:

                  some-container/Parent/child1.jpg
                  some-container/Parent/child2.txt
                  some-container/Parent/child3.pdf
                  

                  正如您在上面看到的那样,文件夹 Parent 已创建.

                  As you can see above the folder Parent was created.

                  我正在使用它在 blob 中创建文件:

                  I am using this to create the files in blob:

                              using (var stream = entry.Open ()) {
                                  //check for file or folder and update the above blob reference with actual content from stream
                                  if (entry.Length > 0) {
                                      await blob.UploadFromStreamAsync (stream);
                                  }
                              }
                  

                  这是完整的来源:

                  [FunctionName ("OnUnzipHttpTriggered")]
                  public static async Task<IActionResult> Run (
                      [HttpTrigger (AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
                      ILogger log) {
                      log.LogInformation ("C# HTTP trigger function processed a request.");
                  
                      var requestBody = new StreamReader (req.Body).ReadToEnd ();
                      var data = JsonConvert.DeserializeObject<ZipFileMetaData> (requestBody);
                      var storageAccount =
                          CloudStorageAccount.Parse (Environment.GetEnvironmentVariable ("StorageConnectionString"));
                      var blobClient = storageAccount.CreateCloudBlobClient ();
                      var container = blobClient.GetContainerReference (data.SourceContainer);
                      var blockBlob = container.GetBlockBlobReference (data.FileName);
                      var extractcontainer = blockBlob.ServiceClient.GetContainerReference (data.DestinationContainer.ToLower ());
                      await extractcontainer.CreateIfNotExistsAsync ();
                  
                      var files = new List<string> ();
                      // Save blob(zip file) contents to a Memory Stream.
                      using (var zipBlobFileStream = new MemoryStream ()) {
                          await blockBlob.DownloadToStreamAsync (zipBlobFileStream);
                          await zipBlobFileStream.FlushAsync ();
                          zipBlobFileStream.Position = 0;
                          //use ZipArchive from System.IO.Compression to extract all the files from zip file
                          using (var zip = new ZipArchive (zipBlobFileStream)) {
                              //Each entry here represents an individual file or a folder
                              foreach (var entry in zip.Entries) {
                                  files.Add (entry.FullName);
                                  //creating an empty file (blobkBlob) for the actual file with the same name of file
                                  var blob = extractcontainer.GetBlockBlobReference (entry.FullName);
                                  using (var stream = entry.Open ()) {
                                      //check for file or folder and update the above blob reference with actual content from stream
                                      if (entry.Length > 0) {
                                          await blob.UploadFromStreamAsync (stream);
                                      }
                                  }
                  
                                  // TO-DO : Process the file (Blob)
                                  //process the file here (blob) or you can write another process later
                                  //to reference each of these files(blobs) on all files got extracted to other container.
                              }
                          }
                      }
                  
                      return new OkObjectResult (files);
                  }
                  

                  推荐答案

                  只要在入口名前加上目录名,就可以看到自动创建的目录了.

                  Simply add directory name before entry name, and we can see the directory created automatically.

                  var blob = extractcontainer.GetBlockBlobReference ("Parent/"+entry.FullName);
                  

                  请注意,该目录是虚拟的.Blob Storage是container/blob结构,目录其实就是blob名称的前缀,Storage service会根据/分隔符为我们展示目录结构.

                  Note that the directory is virtual. Blob Storage is in container/blob structure, the directories are actually prefixes of blob names, and Storage service displays the directory structure according to the / separator for us.

                  这篇关于如何在 Blob 存储中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)

                        <small id='Oyyi5'></small><noframes id='Oyyi5'>

                          <tbody id='Oyyi5'></tbody>
                          <bdo id='Oyyi5'></bdo><ul id='Oyyi5'></ul>
                          1. <i id='Oyyi5'><tr id='Oyyi5'><dt id='Oyyi5'><q id='Oyyi5'><span id='Oyyi5'><b id='Oyyi5'><form id='Oyyi5'><ins id='Oyyi5'></ins><ul id='Oyyi5'></ul><sub id='Oyyi5'></sub></form><legend id='Oyyi5'></legend><bdo id='Oyyi5'><pre id='Oyyi5'><center id='Oyyi5'></center></pre></bdo></b><th id='Oyyi5'></th></span></q></dt></tr></i><div id='Oyyi5'><tfoot id='Oyyi5'></tfoot><dl id='Oyyi5'><fieldset id='Oyyi5'></fieldset></dl></div>
                            <tfoot id='Oyyi5'></tfoot>

                            <legend id='Oyyi5'><style id='Oyyi5'><dir id='Oyyi5'><q id='Oyyi5'></q></dir></style></legend>