The library consists of two major components: the ResumableDownloadActionFilter and a result inheriting from ResumableDownloadResult.

 

Resumable Action Filter

The ResumableDownloadActionFilter (likely to be renamed as this project approaches a well tested, stable release) is used to mark an Action in your controller as capable of responding to client requests for partial content. These clients include iOS-based media devices (iPhone, iPad, iPod Touch), Windows Media Player (when accessing the resource directly), Safari web browser, Adobe PDF Reader, almost all download managers, etc.

The only required parameter for the action filter is a string which provides the name of the ResumableDownloadRequest-based object you want provided to your action method as a parameter.

[ResumableDownloadActionFilter("resumableRequestParameter")]
public ActionResult Media(ResumableDownloadRequest resumableRequestParameter)
{
// Method Body
}

 

Decorating your action like the above code snippet will result in the default ResumableDownloadRequest object being created and populated with any relevant information it can parse from the client request. The object is passed to a ResumableDownloadResult which will handle returning full content, a requested range of content or a multipart message containing the requested ranges of content.

The second constructor for the action filter allows a developer to pass in an object type to be used to hold the parsed information from the client request. In this case simply create a new class derived from ResumableDownloadRequest and add whatever properties and methods are needed. Supply the type to the action filter and this will be the object passed to the action method.

 

[ResumableDownloadActionFilter("resumableRequestParameter", typeof(CustomResumableRequest))]
public ActionResult Media(ResumableDownloadRequest resumableRequestParameter)
{
// Method Body
}

 

[ResumableDownloadActionFilter("resumableRequestParameter", typeof(CustomResumableRequest))]
public ActionResult Media(CustomResumableRequest resumableRequestParameter)
{
// Method Body
}

In the above snippets, it might be better to use the first style. If the supplied type can't be instantiated and cast to the required ResumableDownloadRequest object the action filter will create the default type to be used instead. Using the base object as the action parameter type ensures the receipt of an object with the parsed information and gives the developer the flexibility to check for the correct type before casting and populating additional data.

The second style will give pass the correct object as long as the preconditions are met: the object type can be instantiated by the action and the object can be cast to the ResumableDownloadRequest base type. Using this style the action method body will not need to do any further casting.

 

Resumable Download Result

 

Coming Soon.

Last edited Nov 24, 2010 at 7:50 PM by VikingErik, version 4

Comments

No comments yet.