# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.laminar.run/advanced/uploading-and-downloading-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
