# Using files in your builds

There are multiple ways to use files in your Bitrise builds.

- Most Steps that generate files store the filepath in an output Environment Variable (Env Var). Subsequent Steps in the same Workflow can re-use that Env Var to access the file.
- You can [upload a file to the Generic File Storage](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds) and use the automatically generated Env Var as a Step input value in Steps that accept URLs as an input.
- You can [upload a file to the Generic File Storage](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds) and use one of our Steps (for example, the [**File Downloader**](https://github.com/bitrise-steplib/steps-file-downloader) Step) to download the file for the build. This works with Steps that require local file paths and as such do not support URLs directly as the input value.

## Downloading a file using the File Downloader Step

One of the ways to access a file in your build is by using the **File Downloader** Step. This Step is useful when you need to use a file in a Step input that only accepts local paths as a value.

The Step downloads the file in a location you specify, and then every subsequent Step can access the file in that location.

**Workflow Editor**

1. Open the Workflow Editor.
1. Add the **File Downloader** Step to your Workflow.
1. In the **Download source URL** input, add the location where the file can be found.

   :::note[Finding the download URL for an uploaded file]

   If you [uploaded the file to Bitrise](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds), you can find its download URL in the **Files** section of the **Project settings** page.

   :::
1. In the **Download destination path** input, specify the path where you want to download the file. It should be a path relative to the root of the repository.

   :::tip[Using an Env Var as the input value]

   You can store the filepath in an App Env Var instead of specifying it directly for the input. That way you can refer to the file through the Env Var in other Steps, you won’t have to specify the path every time.

   For example, if you store the path in the `BITRISEIO_MY_FILE_LOCAL_PATH` Env Var, you can use it as the path for the input, and also use it to access the file in every subsequent Step.

   :::
1. Click **Save changes** in the top right corner.

**Configuration YAML**

1. Open the app's `bitrise.yml` file.
1. Add the `file-downloader` Step to your Workflow.

   ```yaml
   workflows:
     download:
       steps:
       - activate-ssh-key: {}
       - git-clone: {}
       - file-downloader:
           inputs:
   ```
1. In the `source` input, add the location where the file can be found.

   ```yaml
   workflows:
     download:
       steps:
       - activate-ssh-key: {}
       - git-clone: {}
       - file-downloader:
           inputs:
           - source: "$BITRISEIO_BITRISE_TEST_URL"
   ```
1. In the `destination` input, specify the path where you want to download the file. It should be a path relative to the root of the repository.

   ```yaml
   workflows:
     download:
       steps:
       - activate-ssh-key: {}
       - git-clone: {}
       - file-downloader:
           inputs:
           - destination: "/"
           - source: "$BITRISEIO_BITRISE_TEST_URL"
       - deploy-to-bitrise-io: {}
   ```

   :::tip[Using an Env Var as the input value]

   You can store the filepath in an App Env Var instead of specifying it directly for the input. That way you can refer to the file through the Env Var in other Steps, you won’t have to specify the path every time.

   For example, if you store the path in the `BITRISEIO_MY_FILE_LOCAL_PATH` Env Var, you can use it as the path for the input, and also use it to access the file in every subsequent Step.

   :::

## Downloading a file using a custom Script Step

If you don't want to use the **File Downloader** Step to download and access an uploaded file in your build, you can use your own custom Script Step as well. All you need to do is to get the download URL and then download the file by specifying a full download path that exists on the build machine.

**Workflow Editor**

1. 1. Log in to Bitrise and select **Bitrise CI** on the left, then select your project.
1. Click the **Workflows** button on the main page.
1. Add a **Script** Step to your Workflow.
1. Find the **Script content** input of the Step.
1. Add a script to download the file and store the destination path in an Env Var.

   :::tip[Uploading the file to Bitrise]

   If you [upload the file to Bitrise](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds), you can use the file's download URL in your script.

   :::

   In the example below, the download URL is stored in the BITRISEIO_MY_FILE_ID_URL Env Var. We're using envman to store the destination path in the BITRISEIO_MY_FILE_LOCAL_PATH Env Var. Subsequent Steps can use this Env Var to access the file.

   ```bash
   #!/bin/bash
   set -ex

   # specify local download path
   export file_local_path=download/path/to/my/file

   # download the file
   wget -O "$file_local_path" "$BITRISEIO_MY_FILE_ID_URL"
   echo "file downloaded to: $file_local_path"

   # OPTIONALLY: export the file's local path, to be able to use it in subsequent steps as an input value
   envman add --key BITRISEIO_MY_FILE_LOCAL_PATH --value "$file_local_path"
   ```

   Alternatively, for example, you can set the location as an App Env Var and simply download it to that path instead of defining the path inside the Script Step.

**Configuration YAML**

1. Open the `bitrise.yml` file of your app.
1. Add a `script` Step to your Workflow.

   ```yaml
   my-workflow:
     steps:
       script:
         inputs:
         - content:
   ```
1. In the `content` input, add a script to download the file and store the destination path in an Env Var.

   :::tip[Uploading the file to Bitrise]

   If you [upload the file to Bitrise](/bitrise-ci/run-and-analyze-builds/managing-build-files/uploading-files-for-your-builds), you can use the file's download URL in your script.

   :::

   In the example below, the download URL is stored in the BITRISEIO_MY_FILE_ID_URL Env Var. We're using envman to store the destination path in the BITRISEIO_MY_FILE_LOCAL_PATH Env Var. Subsequent Steps can use this Env Var to access the file.

   ```yaml
   my-workflow:
     steps:
       - script:
           inputs:
           - content:
           #!/bin/bash
           set -ex

           # specify local download path
           export file_local_path=download/path/to/my/file

           # download the file
           wget -O "$file_local_path" "$BITRISEIO_MY_FILE_ID_URL"
           echo "file downloaded to: $file_local_path"
   ```

   Alternatively, for example, you can set the location as an App Env Var and simply download it to that path instead of defining the path inside the Script Step.
1. Optionally, export the file's local path so you can use it in subsequent Steps in the same Workflow.

   ```yaml
   my-workflow:
     steps:
       - script:
           inputs:
           - content:
           #!/bin/bash
           set -ex

           # specify local download path
           export file_local_path=download/path/to/my/file

           # download the file
           wget -O "$file_local_path" "$BITRISEIO_MY_FILE_ID_URL"
           echo "file downloaded to: $file_local_path"

           # export the file path for subsequent steps
           envman add --key BITRISEIO_MY_FILE_LOCAL_PATH --value "$file_local_path"
   ```
