Programming the Mobile Web : Content Delivery (part 2) - File Delivery

2/4/2011 4:46:35 PM

2. File Delivery

To deliver a file, there are three models:

  • Direct linking

  • Delayed linking

  • OMA Download

You can use any of these three methods to deliver the files, either using the physical file (video, audio, game, etc.) directly or via a script (PHP, ASPX, etc.). If you use a script to deliver a file, you can log, secure, and even charge for every download. If the file is available directly through the web server, anyone with the URL can download the file.


The installation of files using HTTP is also called OTA (Over-the-Air) provisioning. Some low-end devices don’t have a web browser but do have the ability to download files (e.g., ringtones, applications, or images) using HTTP. We can offer files to those devices, but we must send the download URLs by WAP Push using SMS.

2.1. Direct linking

Direct linking is the simplest way to deliver content. A direct link is just a link to the file (with the right MIME type defined), a link to a script that will deliver the file, or a link to a script that will redirect the user to the file. For example:

<a href="game.jad">Download This Game</a>
<a href="download.php?id=22222">Download This Game</a>

The download.php script can save the download to the database, check permissions, and then deliver the content using the appropriate MIME type, writing the file to the response output or redirecting the browser to the file:

if ($everything_ok) {
header('Location: game.jad');
} else {
header('Location: download_error.php');

2.2. Delayed linking

Delayed linking is a technique often used in download sites for desktop browsers. It allows us to show a landing page before the download starts. This landing page will also be the document the user will see after the download has finished or, if the browser supports background downloading, while it is downloading.


Some devices also look for the type attribute in a link to decide how to manage the link before downloading the response from the server. For example, we can define a link as a Java ME JAD file using:

<a href="game.jad"
type="application/"> Download This Game</a>

The technique involves linking to an XHTML document that will show the user some information and will use a refresh metatag to redirect the user to the direct link in X seconds (more than 5 for mobile devices).

So, the download page will redirect to:

<a href="download.html">Download This Game</a>

And download.html will contain code like the following:

<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="5;game.jad" />
<title>Download File</title>

<h1>Your game is being downloaded</h1>
<p>If the file is not downloaded in 5 seconds,
<a href="game.jad">click here</a>

<h2>Brought to you by "Your favourite ad here"</h2>

<p>Trouble downloading this game? <a href="sms:611">Send us an SMS</a>
<a href="tel:611">Call Us</a></p>

<a href="/">More Downloads</a>

2.3. OMA Download

OMA Download is a standard defined in 2004 by the Open Mobile Alliance to allow us more control over the delivery of media objects. It also has support for Digital Rights Management (DRM) in two versions, OMA DRM 1.0 and OMA DRM 2.0.


Many browsers support the download of Multimedia Messaging Services (MMS) templates using a format called the Synchronized Multimedia Integration LanguageNokia tools available at (SMIL). This is useful if you are offering templates like postcards. You can create messages using

OMA Download adds two phases to the download process: before download and after download.

The before download process involves a description file downloaded using HTTP before the real file is downloaded. This description file is an XML file containing metainformation for the operating system and instructions for doing the download. This process gives the user an opportunity to see information about the content (name, compatibility, size) before accepting it, as shown in Figure 1.


Using OMA DRM you can protect a file from being sent by MMS, Bluetooth, or any other method after it has been installed on the device. This is to avoid piracy of video, music, Flash Lite, and other multimedia content. Nokia, Sony Ericsson, and Motorola devices are known to have support for this standard.

The after download process involves an HTTP request posted to your web server from the operating system, confirming the final status of the download. This allows you to confirm that the file has been correctly downloaded and installed.

Figure 1. With OMA Download we can give the user more information about the content before she downloads it.

OMA DRM supports the ability to define the right to play, display, or execute a media object or a file a limited number of times. DRM should be managed with care, and you need to test compatibility with the devices you’re targeting before using it.


Sprint, a U.S. carrier, uses a similar format called General Content Descriptor (GCD). A GCD file is a text file with a .gcd extension that is very similar to the JAD file in Java ME.

2.3.1. Download descriptor

The descriptor is an XML-based file that should be served using the MIME type application/vnd.oma.dd+xml.

Here’s a simple example of this file:

<?xml version="1.0"?>
<media xmlns="">
<name>The first man on the moon</type>

These are the typical attributes: name, the user-readable name of the content file; type, the MIME type of the file; objectURI, the absolute URL of the file; size, the file size expressed in KB; and installNotifyURI, the URL that will receive the after-download status (this can have GET parameters defined dynamically to log whether or not the download was saved).

Additional properties are also available, like nextURL (the URL of a website to visit after the download has finished), description (a short description of the media file), vendor (the organization providing the file), and iconURI (an optional icon to be shown with the file information).


There are good resources and tools on the Forum Nokia, Sony Ericsson, and Adobe websites about OMA Digital Rights Management. You can find more information at

2.3.2. Post-download status report

If you define the installNotifyURI in the download descriptor, you will receive a POST request to that URL when the download finishes. This URL will receive as the POST body an integer code with a status message. The important thing is that this request does not come in the normal URL-encoded way, so you can’t use the typical $_FORM or Request.Form. To read the status code, you’ll need to read the request body in a low-level format. Table 1 lists the most common OMA Download status codes to read in our scripts.

Table 1. OMA Download status codes
900SuccessThe object was downloaded and installed.
901Insufficient MemoryThe device has no space to download or install the file.
902User CancelledThe user cancelled the download.
903Loss of ServiceThe device lost the network connection while downloading the file.
905Attribute MismatchThe file doesn’t match the download descriptor (e.g., the MIME type). The file will be rejected.
906Invalid DescriptorThe download descriptor is invalid.
951Invalid DDVersionThe download descriptor version is invalid.
952Device AbortedThe device aborted the installation process. This can occur for different reasons.
953Non-Acceptable ContentThe device cannot use the file.
954Loader ErrorThe URL of the file is not working.

To read the OMA Download response from a PHP script, you can use the following sample code:

// We get the post body from the input
$post = file_get_contents('php://input');
// We get the first three characters without spaces
$status = substr(trim($post), 0, 3);

if ($status==900) {
// Download OK, save information to the database
} else {
// Some error happens, save information to the database
// to allow the same user to download it again


If you are delivering premium content that the user has paid for, if the download fails you should deliver the same content without forcing the user to pay again. Even if the download has succeeded, many carriers insist that the content be made available free of charge for 24 hours (or even up to a week). Some new application stores also allow the users to download the premium content again even if they change their mobile devices.


Remember that you can check for OMA Download compatibility using WURFL, DeviceAtlas, or another library before using this download mechanism.

Table 2 reports on browser compatibility with OMA Download.

Table 2. OMA Download compatibility table
Browser/platformOMA Download compatibility
Android browserNo
Nokia Series 40Yes
BlackBerryDepends on the device
Openwave (Myriad)Yes
Internet ExplorerDepends on the device
Motorola Internet BrowserDepends on the device
Opera MobileNo
Opera MiniNo

  •  Programming the Mobile Web : Content Delivery (part 1) - Defining MIME Types
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 3)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 2)
  •  iPhone Application Development : Using Switches, Segmented Controls, and Web Views (part 1)
  •  iPhone Application Development : Using Advanced Interface Objects and Views - User Input and Output
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 2)
  •  Windows Phone 7 Development : Wiring Up Events to an Application Bar ( part 1) - Reacting to Add Button Events
  •  Adding an Application Bar to a Windows Phone 7 Application (part 3) - Adding an Application Bar Using Managed Code
  •  Adding an Application Bar to a Windows Phone 7 Application (part 2) - Adding a Local Application Bar Using XAML & Adding Menu Items
  •  Adding an Application Bar to a Windows Phone 7 Application (part 1) - Adding Images for Use with Application Bar Buttons & Adding a Global Application Bar Using XAML
  •  iPhone Application Development : Creating and Managing Image Animations and Sliders (part 3) - Finishing the Interface
  •  iPhone Application Development : Creating and Managing Image Animations and Sliders (part 2) - Adding an Image View
  •  iPhone Application Development : Creating and Managing Image Animations and Sliders (part 1)
  •  iPhone Application Development : User Input and Output
  •  Windows Phone 7 : Using Accelerometer Data to Move a Ball
  •  Server-Side Browser Detection and Content Delivery : Mobile Detection (part 4) - Device Libraries
  •  Server-Side Browser Detection and Content Delivery : Mobile Detection (part 3) - Transcoders
  •  Server-Side Browser Detection and Content Delivery : Mobile Detection (part 2) - Detecting the Context
  •  Server-Side Browser Detection and Content Delivery : Mobile Detection (part 1) - HTTP
  •  Using Windows Phone 7 Technologies : Retrieving Accelerometer Data (part 2)
    Top 10
    Creative software
    Getting the Most Out of the Microsoft Outlook Client : Using Cached Exchange Mode for Offline Functionality
    User Account Control Is More Than You Think
    Programming with DirectX : Game Input - Win32 Input
    Sharepoint 2007: Upload a File - Upload a File from the Web Interface
    Miscs Apps for iOS Device (April 2012) : SleepKeeper, Cristiano Ronaldo, NatureTap
    The New iPad: answer your questions
    SharePoint 2010 : Securing SharePoint’s SQL Server Installation
    Synchronizing Mobile Data - Using Merge Replication (part 2) - Programming for Merge Replication
    Programming Microsoft SQL Server 2005 : FOR XML Commands (part 3) - OPENXML Enhancements in SQL Server 2005
    Most View
    Wall Street’s “Technology Bubble” 2.0
    Securing Windows Server 2008 in the Branch Office
    Advanced ASP.NET : Component-Based Programming - Properties and State
    SharePoint 2010 : Outlining the Inherent Threat in SharePoint Web Traffic
    The ASP.NET AJAX Control Toolkit (part 3) - The AutoCompleteExtender
    Encrypt Your Entire Hard Drive with FileVault
    iPhone 3D Programming : Holodeck Sample (part 4) - Replacing Buttons with Orientation Sensors
    Infrastructure Security: The Network Level
    IIS 7.0 : Managing Configuration - Delegating Configuration (part 1)
    Performing a typical Exchange Server 2010 install
    Integrating Exchange 2010 with SharePoint 2010
    Angry Bird Space - They are back (Part 2)
    Mobile Payment: a future without a wallet
    Mobile SEO
    Understanding IIS 7.0 Architecture : Non-HTTP Request Processing
    The choices of mobile computing for SOHO users (part 2)
    Upgrading to Windows 8
    ASP.NET and AJAX
    Building Android Apps : Detecting Browsers with WURFL
    SQL Server 2008 Command-Line Utilities : The bcp Command-Line Utility