Setup FileHandler
FileHandler Factory Method
Some of the data of your business domain might be binary data or files. These are handled by a FileHandler. You set up a FileHandler by providing the RuntimeConfig with a factory method that returns a FileHandler implementation. This is the place to
- decide which of the
FileHandlerimplementations ActiveQL provides you want to you use or - provide your own
FileHandlerimplementation. - Provide configuration to the actual
FileHandlerimplementation
These are the FileHandler implementations included in ActiveQL.
ReferenceFileHandler Factory Method (default)
With this FileHandler your API does not handle binary data at. Any file that is part of your business domain is handled as an URL. The client is responsible for storing and securing files itself. The ReferenceFileHandler will just validate that any File attribute is a valid URL.
The following configuration would result in the same Runtime as leaving the fileHandler property empty.
export const runtimeConfig: RuntimeConfig = {
domainGraph: domainGraphBuilder.getDomainGraph(),
fileHandler: () => new ReferenceFileHandler()
};Upload FileHandler Factory Method
Although it is not recommended for production API to directly upload files via API, ActiveQL comes with an UploadFileHandler that does exactly that.
const config:UploadFileHandlerConfig = {
filesPath: 'files/entities',
publicPath: 'public'
}
export const runtimeConfig: RuntimeConfig = {
domainGraph: domainGraphBuilder.getDomainGraph(),
fileHandler: () => new UploadFileHandler(config)
};This configuration would accept files uploaded via multipart/form-data and allow to download them under http://localhost:4000/public/... , assuming your ActiveQLServer runs on localhost:4000.
| Option | Type | Default | Description |
|---|---|---|---|
| filesPath | string | files/entities | the path your server stores the uploaded files |
| url | string | same as Express http server of the ActiveQLServer | the URL your server serves downloads |
| publicPath | string | public | the path your server serves the files |
LocalFileHandler Factory Method
The LocalFileHandler offers secure URLs for the upload and download of files. These URLs have a limited lifespan and must be queried from a client through your business domain API first.
const config:LocalFileHandlerConfig = {
basePath: `http://localhost:4000`,
rootDir: `${__dirname}/..`,
expirationInSeconds: 60,
publicPath: 'public',
uploadPath: 'upload',
deletePath: 'delete',
}
export const runtimeConfig: RuntimeConfig = {
domainGraph: domainGraphBuilder.getDomainGraph(),
fileHandler: () => new LocalFileHandler(config)
};| Option | Type | Default | Description |
|---|---|---|---|
| basePath | string | http://localhost:4000 | the path your server should serve the secure URLs |
| rootDir | string | ${__dirname}/.. | the folder the files should be stored on your server |
| expirationInSeconds | number | 60 | expiration of URLs, after this time since querying a URL from the API the FileHandler will reject any request |
| publicPath | string | public | results to download URL be like http:localhost:4000/public/... |
| uploadPath | string | upload | results to upload URL be like http:localhost:4000/upload/... |
| deletePath | string | delete | results to delete URL be like http:localhost:4000/delete/... |