How To Take Photographs From Windows 8 Applications And Automatically Upload Them To The Cloud–Part 1 of 6
- This post will provide techniques that you can use to take and automatically upload photographs from Windows 8 applications.
- The techniques presented can be used to upload practically anything to the cloud.
- PDFs, Videos, Word Documents, Web Pages, JavaScript js files, etc
- Nick Harris did a great job delivering this content (and more) at TechEd North America and Europe. You can read more here: https://www.nickharris.net/
- Windows 8 is a connected operating system.
- It has been from the ground up to interface with the web and networking in general.
- 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.
- 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.
- 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.
- For this blog series we will use block blobs.
- You will need an Azure Account to do these 6 posts. Sign up now here.
Free 90-day trial for Windows Azure | https://www.microsoft.com/click/services/Redirect2.ashx?CR_CC=200114759 |
Visual Studio 2012 RC For Windows 8 | https://www.microsoft.com/click/services/Redirect2.ashx?CR_CC=200114760 |
Figure 1: The inefficient approach to uploading photos
- 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.
- 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.
- 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.
- Once the Windows 8 application has the Shared Access Signature, it can write directly to blob storage.
- 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
- Figure 2 represents the steps needed to get the Shared Access Signature (SAS) to the Windows 8 Application.
- 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.
- In short, the Windows 8 application requests an SAS from a web role.
- The web role then sends the SAS to the Windows 8 application.
- 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
- 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.
- I'll show this with code.
- By specifying a Shared Access Signature, you can give the Windows 8 application access to a blob container for a specified period of time.
- 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.
- The SAS token appears as part of the resource's URI as a series of query parameters.
- 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
- A Hosted Service
- It will be needed to create two things at the portal
- 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.
- We will need to sign up for an Azure Trial Account