Downloading a file
To download a file from an Encyclopedia volume, identify the file and indicate whether to embed the content in the response or use chunked transfer encoding. In HTTP 1.0, you must embed the entire file in the response and send it in a long, uninterrupted file stream. In HTTP 1.1, you can send the file in smaller chunks, which increases the efficiency of the file transfer. Although the Encyclopedia volume supports both methods, BIRT iHub messages typically use chunked transfer encoding.
The following example application uses chunked transfer encoding and relevant com.actuate.schemas classes to build an application that downloads a file from an Encyclopedia volume.
Using DownloadFile
The DownloadFile class downloads a file from an Encyclopedia volume to the client. You can choose to embed the file content in the response or send it to the client as an attachment.
The DownloadFile class contains the following list of attributes:
*FileName or FileId is a string specifying the ID or name of the file to download.
Specify either FileName or FileId.
*DecomposeCompoundDocument is a Boolean indicating whether to download a compound document as one file or multiple attachments.
If the DecomposeCompoundDocument value is False, you can download the file as a single file. If the value is True, and the file is a compound document, the Encyclopedia volume splits the file into attachments containing the atomic elements of the compound document such as fonts and images. A decomposed document is not in a viewable format. The default value is False.
*DownloadEmbedded is a Boolean indicating whether to embed the content in the response or use chunked transfer encoding.
*FileProperties is a string array specifying the file properties to return.
How to build an application that downloads a file
The following application derives from the code in the BIRT iHub Integration Technology example applications for the MS .NET Client. In the example application, AcDownloadFile_Chunked class, downloads a file from the Encyclopedia volume, using the chunked option, and saves the file in the specified directory.
The AcDownloadFile_Chunked class performs the following operations:
*Instantiates an ActuateAPIEx object for specifying the Actuate IDAPI SOAP header extension elements, such as AuthId
namespace Actuate
{
class AcDownloadFile_Chunked
{
ActuateAPI l_proxy;
ActuateAPIEx l_proxyEx= new ActuateAPIEx( );
l_proxyEx.Url = l_proxy.Url;
l_proxyEx.HeaderValue = new Header( );
l_proxyEx.HeaderValue.AuthId =
l_proxy.HeaderValue.AuthId;
*Prepares the DownloadFile request by instantiating DownloadFile and DownloadFileResponse objects, then specifying the file name, item type, and option to download an embedded file
DownloadFile l_req = new DownloadFile( );
l_req.Item = l_filename;
l_req.ItemElementName = ItemChoiceType34.FileName;
l_req.DownloadEmbedded = false;
DownloadFileResponse l_res;
*Performs the DownloadFile administration operation by making the download file proxy call and handling any exceptions
try
{
l_res = l_proxyEx.downloadFile(l_req);
}
catch(Exception e)
{
PrintExceptionDetails(e);
return;
}
*Saves the downloaded file to the specified location and closes the file stream
FileStream l_fileStream = new FileStream(l_directory + "\\"
+ l_filename.Substring(l_filename.LastIndexOf("/")+1),
FileMode.Create);
((MemoryStream) ActuateAPIEx.DownloadStream).WriteTo(l_fileStream);
l_fileStream.Close( );