Windows Azure Storage BLOBs How to add a child folder

Source: Internet
Author: User
Keywords Azure azure blobs sub Folder

As mentioned in the Windows Azure Storage BLOB Overview, Windows Azure Storage Blobs does not have the concept of a subfolder, which is part of the file name. For example

Http://myaccount.blob.core.windows.net/pictures/trips/seattle/spaceneedle.jpg

At first glance you might think that there are multiple tree-level folders "Pictures", "trips" and "Seattle" that correspond to the namespace of this blob, but in fact many of the members in all the paths are only the names of the binary files themselves. In this example, the name of the container (container) is "pictures" and the stored binary file name is "Trips/seattle/spaceneedle.jpg".

Attach a Console Mode Creator sample program code to upload a picture img_2956.jpg on a local hard drive to Windows Azure Storage a container named Image (Container), and this BLOB File name is Subfolder1\subfolder1a\img_2956.jpg

Using System;

Using System.Collections.Generic;

Using System.Linq;

Using System.Text;

Add some namespace
Using System.Configuration;

Using Microsoft.WindowsAzure.Storage;

Using Microsoft.WindowsAzure.Storage.Auth;

Using Microsoft.WindowsAzure.Storage.Blob;


Namespace Blobsample
{

Class Program

{

static void Main (string] args)

{

Retrieve Storage account from connection string.
Cloudstorageaccount Storageaccount = Cloudstorageaccount.parse ("DEFAULTENDPOINTSPROTOCOL=HTTPS; Accountname=[your account name]; Accountkey=[your Key] ");

Create the BLOB client.
Cloudblobclient blobclient = Storageaccount.createcloudblobclient ();

Retrieve reference to a previously created container.
Cloudblobcontainer container = blobclient.getcontainerreference ("image");

Retrieve reference to a blob named "Subfolder1\\subfolder1a\\img_2956.jpg".
Cloudblockblob Blockblob = container. Getblockblobreference ("subfolder1\\subfolder1a\\img_2956.jpg");

Create or overwrite the "subfolder1\\subfolder1a\\img_2956.jpg" blob with contents to a local file img_2956.jpg.
using (var FileStream = System.IO.File.OpenRead (@ "img_2956.jpg"))

{

Blockblob.uploadfromstream (FileStream);

}

System.Console.WriteLine ("complete!");

System.Console.ReadKey ();

}

}

}

If you use tools such as Cloudxplorer, to make Azure Storage Blobs analog as a file explorer, let the user look like there are two levels of subfolders Subfolder1 and Subfolder1a, but remember that this is actually a container for image ( Container), a binary file named subfolder1\subfolder1a\img_2956.jpg is stored.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.