Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

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

3/4/2011 11:55:18 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server