【问题标题】:Windows Azure: Creating a subdirectories inside the blobWindows Azure:在 blob 中创建子目录
【发布时间】:2023-04-06 18:45:02
【问题描述】:

我想在我的 blob 中创建一些子目录。但是效果不好

这是我的代码

protected void ButUpload_click(object sender, EventArgs e)
    {
        // store upladed file as a blob storage
        if (uplFileUpload.HasFile)
        {
            name = uplFileUpload.FileName;
            // get refernce to the cloud blob container
            CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");

            if (textbox.Text != "")
            {
                name = textbox.Text + "/" + name;
            }
            // set the name for the uploading files
            string UploadDocName = name;

            // get the blob reference and set the metadata properties
            CloudBlockBlob blob = blobContainer.GetBlockBlobReference(UploadDocName);
            blob.Metadata["FILETYPE"] = "text";
            blob.Properties.ContentType = uplFileUpload.PostedFile.ContentType;

            // upload the blob to the storage
            blob.UploadFromStream(uplFileUpload.FileContent);

        }
    }

我所做的是,如果我必须创建一个子目录,我将在文本框中输入子目录的名称。

例如,如果我需要在子目录 "files" 中创建一个名为 "test.txt" 的文件 然后,my textbox.text = filesuplFileUpload.FileName = test.txt

现在我将连接它们并上传到 blob.. 但是效果不好。。 我越来越 https://test.core.windows.net/documents/files/

我没有得到全部 我期待https://test.core.windows.net/documents/files/test.txt

我做错了什么... 如何在 blob 中创建子目录。

【问题讨论】:

    标签: windows azure blob directory


    【解决方案1】:

    您可以使用 blobContainer.ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true });获取您正在寻找的视图(忽略斜线并仅列出所有 blob)。

    【讨论】:

      【解决方案2】:

      乍一看,这段代码看起来不错。在调用 GetBlockBlobReference() 之前,我将逐步检查代码并验证 UploadDocName 是否符合您的预期。

      【讨论】:

        【解决方案3】:

        在执行 GetBlockBlobReference() 后检查 blob.Uri?

        顺便说一句,每次我执行此类代码时,我都会使用 GetBlobReference() 来代替......我想知道那里是否有可能存在差异? (那会非常奇怪。)

        【讨论】:

          【解决方案4】:

          它现在可以工作了……这是我在显示 blob 内容时的错误

          protected void DisplayBlob_click(object sender, EventArgs e)
              {
                  // get container referrence
                  CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents");
          
                  // create list
                  IEnumerable<IListBlobItem> blobList = blobContainer.ListBlobs();
          
                  // display name on the page
                  string names = string.Empty;
          
                  foreach (IListBlobItem item in blobList)
                  {
                      names += item.Uri + "<br />";
          
                  }
          
                  LURI.Text = names;
              }
          

          只显示当前目录,不遍历子目录....

          谢谢....

          【讨论】:

            猜你喜欢
            • 2015-08-02
            • 2011-02-06
            • 2012-12-29
            • 2011-02-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-06-22
            • 2022-01-13
            相关资源
            最近更新 更多