开发者

Windows Azure: Creating a subdirectories inside the blob

I wanted to create some subdirectories inside my blob. But it is not working out well

Here is my code开发者_高级运维

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);

        }
    }

What I did is that, If I have to create a sub directory, I will enter the name of the sub directory in the textbox.

for example, if I need to create a file named "test.txt" inside the sub directory "files" Then, my textbox.text = files and uplFileUpload.FileName = test.txt

Now I will concatenate them and upload to the blob.. But it is not working well.. I am getting just https://test.core.windows.net/documents/files/

I am not getting the entire thing I was expecting https://test.core.windows.net/documents/files/test.txt

What am I doing wrong... How to create sub directories inside the blob.


You can use blobContainer.ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true }); to get the view you're looking for (ignores the slashes and just lists all the blobs).


At first glance, this code looks fine. I would step through the code and verify that UploadDocName is what you expect it to be before you call GetBlockBlobReference().


Check blob.Uri after you do GetBlockBlobReference()?

BTW, every time I do this sort of code, I use GetBlobReference() instead... I wonder if there's some chance there's a difference there? (That would be extremely strange.)


Its working now... It was my mistake in the display the contents of the 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;
    }

which shows only the current directory and doesn't traverse to the subdirectories....

Thanks....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜