Class: cWebResourceManager

Properties  Events  Methods    Index of Classes

The Web Framework resource manager for file download services

Hierarchy

cObject
---cBaseWebComponent
------cWebComponent
---------cWebResourceManager

Library: Web Application Class Library

Package: cWebResourceManager.pkg

Description

The cWebResourceManager class facilitates file downloads. It allows you to generate download URLs for local files. The URL can be used by the client to securely download a file from outside the AppHtml folder. The generated URL points to a path handled by the resource manager using its cWebHttpHandler instance. It communicates with the resource manager to validate the download and retrieve the file path. All details that are needed by the download request are encrypted inside the URL.

Security

Because downloading of files requires access to server folders that do not have direct web-shares, a series of passwords and encryption strategies are used to secure file uploads and downloads.

File uploads and downloads are limited to "registered" (i.e., developer specified) folders and their subfolders. The framework automatically registers a default download and upload folder based on properties and in most cases these default directories will suffice. You can register additional folders as needed. By default, files are downloaded from \Reports\Cache and uploaded to \Data\Uploads. This can be customized with the following interfaces:

cWebResourceManager Class:

RegisterDownloadFolder is used to register a local file path as an accessible download folder.
RegisterUploadFolder is used to register a local file path as an accessible upload folder.
pbRegisterReportsCacheFolder controls whether the default cache folder is registered as a download folder.
pbRegisterUploadsFolder controls whether the default upload folder is registered as an upload folder.
pbAllowNonSessionDownloads controls whether non-session-bound file downloads are allowed.

cWebApp Class:

GetReportsCache determines the path to the default report cache folder.
UploadFolder determines the path to the default upload folder.

See Secure File Streaming for more information.

A standard file streaming script is available in the WebApp framework that is capable of streaming files from the hard drive using ASP. The resource manager object is the central location for handling the file streaming and is available in your application as a global object handle (ghoWebResourceManager).

The DataFlex Report Writer (DR) integration wizard for the Web Framework uses the resource manager to serve reports saved as PDataFlex files to the client.

Sample

Use cWebResourceManager.pkg

Object oWebResourceManager is a cWebResourceManager
End_Object


Normally, you do not need to declare a cWebResourceManager object. The New Web App Wizard will generate one for you and include it in your application.

Downloading a File

In order to download a file from a secure location on the server to a qualified client you generate a special URL via the resource manager that contains an encrypted resource string. This URL can safely be sent to the client. Once the client has this special URL it can be used to load the file from the server in a secure way. The URL is unique to the session ID of the client that was authorized to generate that URL so that it cannot be used by any other client.

Use DownloadURL to generate a unique and secure URL for downloading a file.

Object oButton is a cWebButton
    Set psCaption to "View Prices"

    Procedure Ok
        String sPath sUrl
        Move "c:\Catalog\Pricelist.pdf" to sPath
        // Builds an encrypted URL based on the file path
        Get DownloadURL of ghoWebResourceManager sPath to sUrl
        // load the file in the cWebIFrame object in the frame
        WebSet psUrl of oFrame to sUrl
    End_Procedure
End_object

Object oFrame is a cWebIFrame
End_Object

In the above example, the resource manager is used to generate a download URL for the file "c:\Catalog\Pricelist.pdf". The URL is sent back to the client by setting the psURL web property of a cWebIFrame object. Once the IFrame object receives the new psURL property value, it will automatically request this URL from the server. The server will invoke the resource manager to verify the session ID and stream the requested file.

Use CustomDownloadURL to generate a unique and secure URL with the ability to apply special options, such as: invoking the Save As dialog at the client, changing the file name at the client, allowing the URL to be used with any client session ID, setting a timeout for the URL.

The following example demonstrates how to download a file and invoke the Save As dialog to save it on the client.

Object oButton is a cWebButton
    Set psCaption to "Save Prices"

    Procedure Ok
        String sPath sUrl
        Move "c:\Catalog\Pricelist.pdf" to sPath
        // Builds an encrypted URL based on the file path
        Get CustomDownloadURL of ghoWebResourceManager sPath True "" True 0 to sUrl
        // load the file in the cWebIFrame object in the frame
        Send NavigateToPage to ghoWebApp sUrl btNewWindow
    End_Procedure
End_Object


Post File Download

Augment the FileDownloadFinished method to perform special processing after a file has been successfully sent to the client. For example, you could use this event to keep a log of all downloaded files, or to delete the downloaded file.