File Handlers
- Last UpdatedMay 10, 2023
- 2 minute read
Depending on the properties of a File object in the database, a file is returned using a matching file handler. You can plug in custom file handlers on a per-implementation basis. This is useful, for example, if you have custom cookies or authorization tokens that need to be passed to an endpoint when the file is requested. This is important when viewing files in Accusoft as it is required that the file can be downloaded in the AIM Workhub service and set to the Accusoft conversion services.
To create a custom file handler, you must create a class implementing the IFileHandler interface from the AVEVA.NET.Workhub.Domain assembly and with a constructor that matches the following example:
using AVEVA.NET.Workhub.Domain.FileHandling;
using AVEVA.NET.Workhub.Domain.Models;
using System.Net.Http;
namespace AVEVA.NET.SampleExtension
{
// Class implementing the IFileHandler interface
public class MyFileHandler : IFileHandler
{
public MyFileHandler(IWorkhubSessionRegistry registry,
IFileHandlerConfiguration configurationResolver,
HttpRequestMessage parentRequest)
{
}
public bool CanHandle(Workhub.Domain.Models.ContentFile file)
{
// Check whether the retrieval of this file can be handled
throw new NotImplementedException();
}
public FileContents GetContents(Workhub.Domain.Models.ContentFile file)
{
// Get the contents of the file, the mime type and the stream
throw new NotImplementedException();
}
public FileHandlerDetails GetFileHandlerDetails()
{
// Get the authentication and service name of the handler
throw new NotImplementedException();
}
}
}
To test the handler you have created, ensure that you have a document and file, which
is handled by your file handler. Drop your dll including the file handler into the Bin directory of the AIM Dashboard website and do an IISRESET.
For production, you must package up your file handler with other extensions as part of the Web Deploy package.
Configuring the Sample File Handler
A sample file handler application is shipped along with AIM. The sample application is available in the following installation directory:
[InstallationDirectory]\Dashboard\Samples\SampleFileHandler.zip
To configure the sample application to run with the AIM Dashboard installation:
-
Update the following configuration settings in the sample.config file:
<paths>: base InfoLocator/base url of the files (comma separated values are accepted for multiple files)
<serviceName>: Name of the service that exposes the file handler
<userName>: Username
<password>: Password
<apiKey>: API Key (Optional)Note: The above settings are done as a sample, and similar settings can be configured based on the authentication setup.
For example:
<configuration>
<paths>http://testApp:8099/test.pdf</paths>
<serviceName>SampleLogin</serviceName>
<userName>admin</userName>
<password>admin</password>
<apiKey></apiKey>
</configuration> -
Build the sample application.
-
After the build is successful, use one of the following two approaches to deploy the sample handler:
Manual Deploy:
-
Copy the AVEVA.NET.SampleFileHandler.Extension.dll file to the [application root]\bin directory (C:\inetpub\Dashboard\bin for default installation).
-
Copy the sample.config file to the [application root] directory (C:\inetpub\Dashboard for default installation).
-
Copy the SampleExtension folder available under the application’s App\custom directory to [application root]\App\custom directory (C:inetpub\Dashboard\App\custom for default installation).
Web Deploy Package:
-
Right-click on the project and publish to a web deploy package.
-
Open IIS and import the package.zip file to the AIM Dashboard website directory ([application root], C:\inetpub\Dashboard for default installation).
-
-
Select Start and run IISRESET.
After the setup is complete, the sample application requires any AIM Dashboard user to log in if they access any of the files added under the designated paths. After successful authentication, a cookie is created to identify the user automatically on the subsequent requests.