How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud -- Part 1 http://blogs.msdn.com/b/brunoterkaly/archive/2012/08/25/how-to-take-photographs-from-windows-8-applications-and-automatically-upload-them-to-the-cloud-part-1-of-6.aspx
How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud -- Part 2 http://blogs.msdn.com/b/brunoterkaly/archive/2012/08/26/tet3.aspx
How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud -- Part 3 http://blogs.msdn.com/b/brunoterkaly/archive/2012/08/27/test23.aspx
How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud -- Part 4 http://blogs.msdn.com/b/brunoterkaly/archive/2012/08/28/how-to-take-photographs-from-windows-8-applications-and-automatically-upload-them-to-the-cloud-part-4-of-6.aspx
How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud -- Part 5 http://blogs.msdn.com/b/brunoterkaly/archive/2012/08/29/step-5-of-6.aspx
How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud -- Part 6 http://blogs.msdn.com/b/brunoterkaly/archive/2012/08/29/how-to-take-photographs-from-windows-8-applications-and-automatically-upload-them-to-the-cloud-part-6-of-6.aspx
Introduction
001
  1. This post will provide techniques that you can use to take and automatically upload photographs from Windows 8 applications.
  2. The techniques presented can be used to upload practically anything to the cloud.
    • PDFs, Videos, Word Documents, Web Pages, JavaScript js files, etc
  3. Nick Harris did a great job delivering this content (and more) at TechEd North America and Europe. You can read more here: http://www.nickharris.net/
  4. Windows 8 is a connected operating system.
  5. It has been from the ground up to interface with the web and networking in general.
  6. Storing Photographs in the Cloud
    • The Windows Azure storage service offers two types of blobs, block blobs and page blobs.
    • You specify the blob type when you create the blob.
  7. Page Blobs
    • Page blobs are a collection of 512-byte pages optimized for random read and write operations.
    • Writes to page blobs happen in-place and are immediately committed to the blob.
    • The maximum size for a page blob is 1 TB.
  8. Block Blobs
    • Block blobs let you upload large blobs efficiently.
    • The maximum size for a block blob is 200 GB, and a block blob can include no more than 50,000 blocks.
    • You can set the number of -threads used to upload the blocks in parallel using the ParallelOperationThreadCount property.
    • Block Blobs are appropriate for media file serving, whereas Page Blobs are optimized for other work patterns.
  9. For this blog series we will use block blobs.
  10. You will need an Azure Account to do these 6 posts. Sign up now here.
Free 90-day trial for Windows Azure
image
http://www.microsoft.com/click/services/Redirect2.ashx?CR_CC=200114759
Visual Studio 2012 RC For Windows 8 http://www.microsoft.com/click/services/Redirect2.ashx?CR_CC=200114760

 


Figure 1: The inefficient approach to uploading photos
002
  1. Figure 1 shows one approach (a bad one) to uploading images to the cloud.
    • It illustrates how a web role (our code running inside an IIS process) can be used to accept a byte stream from a Windows 8 application and write that stream to Azure Blob Storage.
    • But this is less than ideal because the Web Role will end up costing a lot of money for the bandwidth.
    • It will also be less scalable because it has to manage all the potential byte streams coming from Windows 8 Applications.
    • A better approach is for the Windows 8 application to directly write to blob storage.
  2. But to make this practical, the Windows 8 application should leverage a special kind of key (like a password of sorts).
    • This special key that gives the Windows 8 application special permission is called a Shared Access Signature.
  3. Shared Access Signature
    • A Shared Access Signature is a URL that grants access rights to blobs.
    • By specifying a Shared Access Signature, you can grant users who have the URL access to a specific resource for a specified period of time.
    • You can also specify what operations can be performed on a resource that's accessed via a Shared Access Signature.
  4. Once the Windows 8 application has the Shared Access Signature, it can write directly to blob storage.
    1. So the first thing the Windows 8 application need to do is to request a shared access signature.

Figure 2: Windows 8 Application Requesting and Receiving Shared Access Signature
003
  1. Figure 2 represents the steps needed to get the Shared Access Signature (SAS) to the Windows 8 Application.
  2. SASs have a limited amount of time that they are valid to use.
    • In other words, they stop working when they expire.
    • This means they should be requested only when they are ready to use.
  3. In short, the Windows 8 application requests an SAS from a web role.
  4. The web role then sends the SAS to the Windows 8 application.
  5. Once the Windows 8 application gets an SAS, it can start reading and writing from and to blob storage.

Figure 3 - Windows 8 Talking Directly to Blob Storage
004
  1. Once the Windows 8 application takes and uploads the photograph, it can mark it as public, meaning that anyone with the url to the photograph can view it.
    1. I'll show this with code.
  2. By specifying a Shared Access Signature, you can give the Windows 8 application access to a blob container for a specified period of time.
  3. Shared Access Signatures allow granular access to tables, queues, blob containers, and blobs.
    • A SAS token can be configured to provide specific access rights, such as read, write, update, delete, etc. to a specific table, key range within a table, queue, blob, or blob container; for a specified time period or without any limit.
  4. The SAS token appears as part of the resource's URI as a series of query parameters.

5 More Posts
005
  1. We have 5 more posts to address
    • We will need to sign up for an Azure Trial Account
      • It will be needed to create two things at the portal
        • A Hosted Service
          • It will be used to host our forthcoming web service in IIS inside of one of several MS data centers
        • A Storage Account
          • It will be used to store pictures taken by our Windows 8 application.
          • It will also be used by Internet users to view these uploaded photographs
    • We will create a Web Service
      • You can typically choose either of these two project types: (1) Windows Communication Foundation (WCF) ; or (2) ASP.NET Web API, which is included with MVC version 4.
      • We will take the newer, more modern concepts that ASP.NET Web API brings to the table, truly embracing HTTP concepts (URIs and verbs).
      • Also, the ASP.NET Web API can be used to create services that use more advanced HTTP features - such as request/response headers, hypermedia constructs.
      • Once we create the web service, it will be ready to support the Windows 8 application.
      • The ASP.NET Web API will return a SAS to the Windows 8 application. That is all it will do.
      • Both projects can be tested on a single machine during development.
      • We will deploy the ASP.NET Web API Web Service to the Hosted Service (created at the portal )indicated above.
    • We will need to create a Windows 8 application that has access to either a USB or built in web cam.
      • The Windows 8 application will automatically request the Shared Access Signature from the web service.
      • It will then use the Shared Account Signature to upload the freshly taken photograph to the Storage Account previously created.