File Handling

Laminar provides mechanisms for handling binary data (files) within your workflows, particularly in conjunction with HTTP requests and shell scripts.

When an http request (using lam.httpRequest) results in a file download, Laminar automatically stores the file and provides a binaryDataId in the step's response.

Sample response for downloading file
{
  "lam.httpStatusCode": 200,
  "lam.httpStatusText": "OK",
  "lam.success": true,
  "lam.binaryDataIndicator": true,
  "lam.contentType": "application/zip",
  "lam.fileName": "fileName",
  "lam.contentLength": 625,
  "lam.binaryDataId": "binaryId"
}

You can access this ID via data.step_N.response['lam.binaryDataId'].

Processing files in script:

To process a downloaded file (or any binary data referenced by a binaryDataId) within a lam.shell script, you must include the binaryDataIds array in your lam.shell definition.

Laminar will make these files available to your shell script in its execution environment.

Example Workflow:

1

Download Report

(data) => {
    // This step simulates downloading a CSV report.
    return {
        "lam.httpRequest": {
            "method": "GET",
            "url": "https://mockserver.com/download-report.csv"
        }
    };
}

After this step executes, data.step_1.response['lam.binaryDataId'] will hold the reference to the downloaded CSV file.

2
(data) => {
    // Get the binaryDataId from the previous step's response (Step 1).
    const downloadedFileId = data.step_1.response['lam.binaryDataId'];
    const fileName = data.step_1.response['lam.fileName'];

    return {
        "lam.shell": {
            // The script will operate on the downloaded file.
            // Laminar makes files referenced by binaryDataIds available by their original names
            // or a generic 'input' if no name is available.
            "script": `
                echo "Processing downloaded file..."
                # Assuming the downloaded file is named 'report.csv' or similar, or just 'input'
                # You might need to inspect the actual filename provided by Lunar in logs.
                cat ${fileName} | wc -l
            `,
            "binaryDataIds": [downloadedFileId],
        }
    };
}

Last updated

Was this helpful?