> For the complete documentation index, see [llms.txt](https://docs.laminar.run/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.laminar.run/advanced/uploading-and-downloading-files.md).

# Uploading and Downloading Files

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.

{% code title="Sample response for downloading file" %}

```json
{
  "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"
}

```

{% endcode %}

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:**

{% stepper %}
{% step %}

### Download Report

```javascript
(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.
{% endstep %}

{% step %}

### Print Report

```javascript
(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],
        }
    };
}
```

{% endstep %}
{% endstepper %}
