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

Copying BLOBs - Copying files via the StorageClient library

3/8/2011 9:43:44 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
You’ve uploaded files and downloaded files in and out of your account. But you don’t always want to transfer files outside your account; sometimes you might want to take a copy of an existing file in the account.

Let’s return to the podcasting example for a lesson on why you might want to do this. Let’s say that during the conversion of a WMA file to MP3, you decide that you don’t want to make the converted file immediately available. In this case, your converted MP3 file would reside in a private container that isn’t available to the general public. At a later date, you decide to make the file available to the public by moving it into your public downloads container. To do this, you copy your converted file from one container to another. Figure 1 shows a file being copied from one container to another.

Figure 1. Copying podcast03.mp3 in the MP3Conversions container to the PublicDownloads container


In figure 1, the BLOB isn’t being uploaded or downloaded; the BLOB podcast01.mp3 is just being copied from the MP3Conversions container and the copy is being placed in the Public-Downloads container.

Although you could do this using a download followed by an upload, this would be much slower than just doing an internal copy within the data center. Likewise, performing an upload followed by a download would be incredibly slow and wasteful of network resources if the calling client was based outside the Windows Azure data center.

Listing 1 shows the code used to copy a very large filename podcast03.mp3 to the PublicDownloads container from the MP3Conversions container via the REST API.

Listing 1. Copying a BLOB between containers

As you can see in listing 1, the basics of making the HTTP request is pretty much the same as any other REST request you’ve made. In this case, you’re setting the destination container as the URI for the request, and you’re setting the request to be a PUT (rather than a GET, HEAD, or POST).

At you set the location of the source BLOB to be copied. The header x-ms-copy-source is where you define the location of the file; notice that we’re including the storage account name (silverlightukstorage), the container (mp3conversions), and the BLOB name (podcast03.mp3) in the header value.

1. Copying files via the StorageClient library

Listing 1 uses the REST API directly to copy the BLOB, but you could make this call by making the simpler StorageClient library call:

var sourceBlob = sourceContainer.GetBlobReference("podcast01.mp3");
var targetBlob = targeCcontainer.GetBlobReference("podcast01.mp3");
targetBlob.CopyFromBlob(sourceBlob);

This code makes the same call as in listing 1, this time using the StorageClient library instead of using the REST API directly.

Note

Although you can use the REST API, using the StorageClient library is much easier. Save yourself a lot of heartache and use the REST API only when necessary. Try to stick to using the lovely StorageClient library.


Snapshotting BLOBs

The problem of copying BLOBs is that you have to pay storage costs to the Microsoft bean counters for keeping duplicate copies of the data. If you’re only copying the BLOB to maintain some sort of version control, you should consider snapshotting instead. A snapshot pins a version of your BLOB at the date and time you created the snapshot. The snapshot is read only (it can’t be modified) and can be used to revert to earlier versions of a BLOB. Only changes made between versions of snapshots are chargeable.

To create a snapshot, you can make the following call:

var snapshotBlob = blob.CreateSnapshot();

To retrieve a snapshot via the REST API, you can use the following URI:

http://accountname.blob.core.windows.net/containername/blobname?snapshot=<DateTime>

You can also retrieve a snapshot using the StorageClient library:

var snapshotBlob = container.GetBlobReference("blobname?snapshot=<DateTime>");

For more details about snapshotting, go to http://msdn.microsoft.com/en-us/library/ee691971.aspx.


Other -----------------
- Using local storage with BLOB storage (part 3) - Improving your handler to check the last modified time
- 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
 
 
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