The Natural Availability Server supports the Natural statement DOWNLOAD PC FILE and transfers the file's content to the browser.
The data file can be downloaded in a format compatible with Entire Connection, or as a CSV file to be opened, for instance, in Microsoft Excel®.
You can configure the default format for the downloaded file via the DOWNLOAD PC FILE statement, using the following properties in the application.properties file:
|
Property name |
Description |
Required |
Default and Optional Values |
|---|---|---|---|
|
|
Defines the format used to save the data file. |
no |
Optional values:
csv (default) |
|
|
Defines the handling of the data file. |
no |
Optional values:
Print |
The Natural Availability Server supports the Natural statement UPLOAD PC FILE and transfers the file's content to Natural.
The uploaded data file can be in a format compatible with Entire Connection, or as a CSV file that matches the previously downloaded file.
An upload dialog opens, when the host expects to receive a file.
Select the file to upload.
Note
The dialog will stay open, if the uploaded file does not match the required format,
followed by an error message. You may repeat, and select a suitable file.
The Natural Availability Server supports the statement Natural PRINT and transfers the file's content to the browser to be printed.
The content of the report can be addressed to a printer installed on the client machine or saved to be processed later.
You can configure the default behavior for the PRINT statement using the following properties:
|
Property name |
Description |
Required |
Default and Optional Values |
|---|---|---|---|
|
|
Defines the handling of the report file. |
no |
Optional values:
Print (default) |
|
|
Defines the format used to save the report file. |
no |
Optional values:
csv |
The browser can handle the download process automatically if a filename is defined in the Natural program using the SET PCFILE command.
To start the download automatically, define the following property:
|
Property name |
Description |
Required |
Default and Optional Values |
|---|---|---|---|
|
|
Defines whether the download will start automatically, or if a download dialog allows the user to configure the behavior for the file. |
no |
false (default) |
Note
This property affects the DOWNLOAD PC and PRINT statements differently.
DOWNLOAD PC FILE statement
If the property is set to "true" the download starts automatically.
PRINT statement
The content transfers automatically to the client and opens the print dialog.
With HTTP data transfer, you can interact with an external HTTP server during file transfer operations.
The external HTTP server is configured through the COMMAND clause of the
DOWNLOAD PC FILE before the
file transfer operation begins.
The HTTP requests to the external server are executed by the local browser. These requests are not executed by the Natural Availability Server.
From a Natural user's perspective, HTTP data transfer can be used with the following statements:
DOWNLOAD PC FILE
The browser sends the file content downloaded with the DOWNLOAD PC FILE
statement to the specified external URL using an HTTP POST request by
default. The HTTP method can be configured to use PUT instead.
UPLOAD PC FILE
The browser sends an HTTP GET request to the specified external URL to
retrieve the file. The retrieved content is then uploaded to Natural.
The following topics are covered below:
The following is an example of a COMMAND clause that can be issued before
the DOWNLOAD PC FILE operation:
DOWNLOAD PC FILE 7 COMMAND 'SET URL 8 DOWN DATA http://localhost:5001/rec1.png' DOWNLOAD PC 8 #PICTURE
In this example, the DOWNLOAD PC FILE operation causes the local browser
to send an HTTP POST request to the specified URL.
The content downloaded from Natural is sent as the request content to the external HTTP server.
By default, the request uses the HTTP POST method. To configure the HTTP
method and content format, see Upload Configuration.
The following is an example of a COMMAND clause that can be issued before
an UPLOAD PC FILE operation:
DOWNLOAD PC FILE 5 COMMAND 'SET URL 6 UP DATA http://localhost:5001/static/return.png' UPLOAD PC FILE 6 #PICTURE
In this example, the UPLOAD PC FILE operation causes the local browser to
send an HTTP GET request to the specified URL. The content returned by the
external HTTP server is then uploaded to Natural.
Since the local browser executes HTTP requests to the external server, the external HTTP server must support Cross-Origin Resource Sharing (CORS).
The browser considers the NHA application and the external HTTP server to be different origins if they use, for example, different domains, ports, or protocols. In this case, the external server must be configured to allow cross-origin requests from the origin of the NHA application.
If CORS is not configured correctly on the external server, the browser will block the request and the HTTP data transfer operation will not be able to communicate with the external server.
Therefore, the external HTTP server should be configured to:
Allow requests from the origin of the NHA application.
Allow the HTTP methods used by the HTTP data transfer operation (such as
GET, POST, or PUT).
Allow any request headers required by the external service.
For example, if the NHA application is running at https://nha.example.com, the external HTTP server must allow requests originating from that address.
The exact CORS configuration depends on the external HTTP server and its security requirements.
Note
CORS configuration is required on the external HTTP server. It is not configured on
the NHA server.
SET PARAM
A COMMAND clause is limited to 80 characters. This limitation can
prevent you from specifying longer URLs or additional parameters required by the
external HTTP server. To address this limitation, you can use the following
SET PARAM command:
DOWNLOAD PC FILE 5 COMMAND 'SET PARAM 6 UP DATA ?param1=no'
The content specified in the SET PARAM command is appended to the URL
defined using the SET URL command.
You can specify multiple SET PARAM commands for the same transfer.
SET TIMEOUT
If the HTTP request takes a long time to complete, you can use the following
SET TIMEOUT command to define the maximum time allowed for the
request:
DOWNLOAD PC FILE 5 COMMAND 'SET TIMEOUT 6 UP DATA 10'
In this example, the timeout for the HTTP request is set to 10 seconds.
When a DOWNLOAD PC FILE operation is used with HTTP data transfer, the
content is downloaded from Natural and then uploaded by the browser to the external HTTP
server.
The following properties refer to the HTTP upload itself, even though the HTTP upload
is part of the DOWNLOAD PC FILE flow.
You can configure the HTTP upload to use different HTTP methods and content formats, allowing integration with external services and APIs that require specific request configurations. To do so, you configure the following properties in the application.properties file:
For the HTTP upload method:
com.softwareag.natural.client.config.data-transfer.external-upload-method=put
Supported values: POST, PUT.
Default: POST.
Defines the HTTP method used by the browser to upload content to an external URL
during a DOWNLOAD PC operation.
For the upload content format:
com.softwareag.natural.client.config.data-transfer.external-upload-content-only=true
Supported values: true, false.
Default: true.
True: The content is uploaded as raw binary (Blob) in the HTTP request body.
False: The content is uploaded using multipart/form-data.