Logo
Lose Weight
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Azure

Managing BLOBs using the StorageClient library (part 2) - Uploading BLOBs & Deleting BLOBs

3/4/2011 11:55:18 AM

2. Uploading BLOBs

To upload files from your web page, you’re going to use the built-in ASP.NET upload control at in listing 1. On click of the upload button at , you’re going to capture the uploaded file and then upload the captured file to BLOB storage. The following listing contains the code-behind for the upload button click event.

Listing 3. Posting the uploaded file to BLOB storage

All the code in listing 3 has been discussed in previous examples, except for what’s happening at and . At you get a reference to the BLOB that you’re about to create. We’re giving the BLOB the original name of the uploaded file (retrieved from the UploadFile control). Then, at you upload the new file to BLOB storage.

Tip

You’ll notice that we’re extracting the filename and the file contents directly from the ASP.NET file upload control. If you want, you can give the file a name different from the original.


Setting the maximum request length

By default, ASP.NET is configured to allow a maximum upload of 4 MB. If you provide a web role frontend to the BLOB storage as we’ve done in this sample, you might need to increase the maximum request length.

To increase the default value to a larger value, you need to add the following line under the system.web element in the web.config file:

<httpRuntime executionTimeout="300" maxRequestLength="51200"/>

The maximum upload size in the above example is 50 MB.


In the previous example, we used the UploadByteArray method to upload the BLOB. Three other methods are provided in the StorageClient library that you can use: UploadFile, UploadText, and UploadFromStream. Depending on your situation, one of these methods might be easier to use than UploadByteArray (for example, UploadFile might be a better choice if you have a local file on disk that you want to store in BLOB storage).

Splitting BLOBs into blocks

The maximum size of a BLOB is 1 TB, but if a file is larger than 64 MB, under the covers the StorageClient library splits the file into smaller blocks of 4 MB each. One of the advantages of the StorageClient library is that you don’t need to worry about this. If you’re using the REST API, you’ll need to implement the splitting of BLOBs into blocks and the committal of blocks and retry logic associated with re-uploading failed blocks (yet another good reason to use the StorageClient library).

If you’re a sick and twisted individual who wants to mess around with blocks, then feel free to look in more detail at the online documentation at http://msdn.microsoft.com/en-us/library/ee691964.aspx.


Now that you’ve spent all that time and effort adding the file to BLOB storage, let’s delete it (groan).

3. Deleting BLOBs

Deleting a BLOB is similar to uploading a file except that you’re deleting the BLOB instead of uploading it (cute, huh?). Just like the upload file example in listing 4, you get the reference to the BLOB, and then delete the BLOB by calling the following: blob.Delete();

The following listing shows the code that will delete the BLOB in your web page.

Listing 4. Deleting the BLOB

As you can see, deleting a BLOB is pretty simple. Now you can list, upload, and delete BLOBs from your storage account using your ASP.NET management website hosted in your Windows Azure web role. Let’s complete the management page example by looking at how you can download BLOBs.

Other -----------------
- Using the REST API (part 2) - Authenticating private requests
- Using the REST API (part 1) - Listing BLOBs in a public container using REST
- The basics of BLOBs - Configuring your application to work against the live service
- The basics of BLOBs : Developing against containers (part 3) - Listing containers & Deleting a container
- The basics of BLOBs : Developing against containers (part 2) - Creating a container
- The basics of BLOBs : Developing against containers (part 1) - Accessing the StorageClient library & Accessing development storage
- The basics of BLOBs : Getting started with development storage
- A closer look at the BLOB storage service
- Storing files in a scaled-out fashion is a pain in the NAS (part 2) - The BLOB service approach to file management
- Storing files in a scaled-out fashion is a pain in the NAS (part 1) - Traditional approaches to BLOB management
 
 
Most view of day
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting ActiveX Security Options
- Microsoft Lync Server 2013 : Persistent Chat Administration (part 1) - Chat Room Management by Administrators
- HP ProLiant Servers AIS : Memory and Cache
- Windows Phone 8 : Scheduled Tasks - Background Agent Types
- SQL Server 2008 R2 : Creating and Managing Stored Procedures - Using System Stored Procedures
- Maintaining Security : Restricting Content in Windows Media Center, Creating Trusted Contacts
- Windows Home Server 2011 : Maintaining Windows Home Server - Checking Free Disk Space on the System Drive
- Exchange Server 2007 : Migrating from Windows 2000 Server to Windows Server 2003 (part 4) - Replacing Existing Domain Controllers
- Microsoft Dynamics AX 2009 : Integration with Microsoft Office - Exporting data to Microsoft Project
- Microsoft Exchange Server 2013 - Managing mailboxes: The essentials (part 2) - Configuring apps for mailboxes
Top 10
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
- MDT's Client Wizard : Application Properties
- MDT's Client Wizard : Operating System Properties
- MDT's Client Wizard : Customizing the Deployment Share
- Windows Server 2012 : Software and User Account Control Administration (part 5) - Maintaining application integrity - Configuring run levels
- Windows Server 2012 : Software and User Account Control Administration (part 4) - Maintaining application integrity - Application access tokens
- Windows Server 2012 : Software and User Account Control Administration (part 3) - Mastering User Account Control - Configuring UAC and Admin Approval Mode
- Windows Server 2012 : Software and User Account Control Administration (part 2) - Mastering User Account Control - Elevation, prompts, and the secure desktop
- Windows Server 2012 : Software and User Account Control Administration (part 1) - Software installation essentials
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro