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

Using local storage with BLOB storage (part 3) - Improving your handler to check the last modified time

3/8/2011 9:39:25 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

5. Improving your handler to check the last modified time

Because you can retrieve the last modified time, you can modify your handler to check whether the file has changed since you last downloaded it. If it has changed, you can download another copy of the file. The following listing shows the modified code for your handler.

Listing 2. Checking the last modified date

At you get the last modified time of the BLOB. 

After you’ve gotten the last modified time of the BLOB, then you check whether you already have the file locally and whether the local file is older than the server file. The final change that you need to make is that you set the last write time of the local file to the last modified time of the BLOB .

So far, we’ve only looked at the properties of a BLOB. Now let’s look at the other part of the BLOB data that’s returned in a HEAD request: custom metadata.

6. Adding and returning custom metadata

In listing 1, we showed you how to view all the headers associated with a BLOB using a console application. In that example, you returned all the standard headers associated with a BLOB (last-modified, x-ms-request-id, and so on). If you want to associate some custom metadata with a file, that metadata would also be displayed in the response headers.

Displaying Custom Metadata

Let’s modify the BLOB podcast01.mp3 to include the author of the file (me) as custom metadata. Figure 3 shows the HEAD response in the same console application using the same code that we developed in listing 2.

Figure 3. HEAD response with custom metadata


Note that with the file podcast01.mp3, there’s a new header returned in the response, called x-ms-meta-author, with the value chris hay. In this example, we returned the metadata from the HEAD request, but it’s also available in a GET request.

Setting Custom Metadata

If you need to set some custom metadata, you can easily do this with the StorageClient library. The following code sets the metadata for the file podcast01.mp3:

blob.Metadata.Add("Author", "Chris Hay");
blob.SetMetadata();

This code calls the UpdateBlobMetadata method on the container, passing in a NameValueCollection of metadata that you want to store against the BLOB.

x-ms-meta

The StorageClient library automatically prefixes all metadata with the tag x-ms-meta-. We actually set the key as author in the metadata collection, but the response header returned x-ms-meta-author. As a matter of fact, the BLOB storage service will only allow you to set metadata with the prefix x-ms-meta- and it ignores any attempt to modify any other header associated with a BLOB. Unfortunately, this means you can’t modify any standard HTTP header that isn’t set by the BLOB storage service.


Scenarios for Using Custom Metadata

The metadata support for BLOBs allows you to have self-describing BLOBs. If you need to associate extra information with a BLOB (for example, podcast author, recording location, and so on), then this would be a suitable place to store that data; you wouldn’t have to resort to an external data source. Any custom attributes associated with a file (such as the author of a Word document) could also be stored in the metadata.

Tip

If you need to be able to search for metadata across multiple BLOBs, consider using an external data source (for example, a database or the Table storage service), rather than searching across the BLOBs.


Now that you know how the upload and download operations operate under the covers, let’s return to the final part of the uploading and downloading puzzle, namely, copying BLOBs.

Other -----------------
- Using local storage with BLOB storage (part 2) - Updating your HTTP handler to use local storage & Checking properties of a BLOB without downloading it
- Using local storage with BLOB storage (part 1) - Using a local cache & Defining and accessing local storage
- Integrating BLOBs with your ASP.NET websites
- Downloading BLOBs
- Managing BLOBs using the StorageClient library (part 2) - Uploading BLOBs & Deleting BLOBs
- Managing BLOBs using the StorageClient library (part 1) - Listing BLOBs using the storage client
- 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
 
 
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