# DownloadObject

Required Frends version: 5.7+

Required .NET version: 8.0

Compatible Agents: Unknown

Source code: <https://github.com/FrendsPlatform/Frends.AmazonS3>

{% tabs %}
{% tab title="Parameter: Input" %}

| Name                                         | Description                                                                                                                                         |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| BucketName : `String`                        | <p>AWS S3 bucket's name.</p><p><br>Default: <code>-</code><br>Example: <code>Bucket</code></p>                                                      |
| SourceDirectory : `String`                   | <p>Downloads all objects with this prefix.</p><p><br>Default: <code>-</code><br>Example: <code>directory/</code></p>                                |
| SearchPattern : `String`                     | <p>String pattern to search objects.</p><p><br>Default:<br><em>Example:</em> <code>.\*, \*file?.txt</code></p>                                      |
| DownloadFromCurrentDirectoryOnly : `Boolean` | <p>Set to true to download objects from the current directory only.</p><p><br>Default: <code>True</code><br>Example: <code>false</code></p>         |
| TargetDirectory : `String`                   | <p>Destination directory where to create folders and files.</p><p><br>Default: <code>-</code><br>Example: <code>c:\temp, \network\folder</code></p> |
| {% endtab %}                                 |                                                                                                                                                     |

{% tab title="Parameter: Connection" %}

| Name                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| AuthenticationMethod : `AuthenticationMethods` | <p>Authentication method to use when connecting to AWS S3 bucket.</p><p>Possible values:</p><ul><li><code>AwsCredentials</code>:</li></ul><p>Authentication method to use when connecting to AWS S3 bucket.</p><ul><li><code>PreSignedUrl</code>:</li></ul><p>Authentication method to use when connecting to AWS S3 bucket.</p><p><br>Default: <code>0</code><br>Example: <code>AwsCredentials</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| 🗝PreSignedUrl : `String`                      | <p>A pre-signed URL allows you to grant temporary access to users who don't have permission to directly run AWS operations in your account.</p><p><br>Default: <code>-</code><br>Example: <code>"<https://bucket.s3.region.amazonaws.com/object/file.txt?X>...</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 🗝AwsAccessKeyId : `String`                    | <p>AWS Access Key ID.</p><p><br>Default: <code>-</code><br>Example: <code>AKIAQWERTY7NJ5Q7NZ6Q</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 🗝AwsSecretAccessKey : `String`                | <p>AWS Secret Access Key.</p><p><br>Default: <code>-</code><br>Example: <code>TVh5hgd3uGY/2CqH</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Region : `Region`                              | <p>AWS S3 bucket's region.</p><p>Possible values:</p><ul><li><code>AfSouth1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApEast1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApNortheast1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApNortheast2</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApNortheast3</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApSouth1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApSoutheast1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>ApSoutheast2</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>CaCentral1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>CnNorth1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>CnNorthWest1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>EuCentral1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>EuNorth1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>EuSouth1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>EuWest1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>EuWest2</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>EuWest3</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>MeSouth1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>SaEast1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>UsEast1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>UsEast2</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>UsWest1</code>:</li></ul><p>AWS S3 bucket's region.</p><ul><li><code>UsWest2</code>:</li></ul><p>AWS S3 bucket's region.</p><p><br>Default: <code>-</code><br>Example: <code>EuCentral1</code></p> |
| {% endtab %}                                   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |

{% tab title="Parameter: Options" %}

| Name                                                  | Description                                                                                                                                                                                                                                                                                                                                                                                                               |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DeleteSourceObject : `Boolean`                        | <p>Delete the S3 source object after download.</p><p>Subfolders will also be deleted if they are part of the object's key and there are no objects left.</p><p>Create subfolders manually to make sure they won't be deleted.</p><p><br>Default: <code>False</code><br>Example: <code>false</code></p>                                                                                                                    |
| ThrowErrorIfNoMatch : `Boolean`                       | <p>Throw an error if there are no objects in the path matching the search pattern.</p><p><br>Default: <code>True</code><br>Example: <code>false</code></p>                                                                                                                                                                                                                                                                |
| ActionOnExistingFile : `DestinationFileExistsActions` | <p>Actions if a destination file already exists.</p><p>Possible values:</p><ul><li><code>Overwrite</code>:</li></ul><p>Actions if a destination file already exists.</p><ul><li><code>Info</code>:</li></ul><p>Actions if a destination file already exists.</p><ul><li><code>Error</code>:</li></ul><p>Actions if a destination file already exists.</p><p><br>Default: <code>1</code><br>Example: <code>Info</code></p> |
| FileLockedRetries : `Int32`                           | <p>For how long will this Task try to write to a locked file.</p><p>Value in seconds.</p><p><br>Default: <code>10</code><br>Example: <code>10</code></p>                                                                                                                                                                                                                                                                  |
| ThrowErrorOnFailure : `Boolean`                       | <p>Throw an error on failure.</p><p><br>Default: <code>True</code><br>Example: <code>true</code></p>                                                                                                                                                                                                                                                                                                                      |
| ErrorMessageOnFailure : `String`                      | <p>Error message to display on failure.</p><p><br>Default: <code>-</code><br>Example: <code>Can't download an object</code></p>                                                                                                                                                                                                                                                                                           |
| {% endtab %}                                          |                                                                                                                                                                                                                                                                                                                                                                                                                           |

{% tab title="Result: Result" %}

| Name                                 | Description                                                                                                                           |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| Success : `Boolean`                  | <p>Task complete without errors.<br>Example: <code>True</code></p>                                                                    |
| Objects : `List<SingleResultObject>` | <p>List of downloaded objects.<br>Example: <code>{ "File.txt", "C:\temp\File.txt", true, false, "Additional information" }</code></p> |
| Error : `Error`                      | <p>Error information if the operation failed.<br>Example: <code>{ "An error occurred", { "ErrorCode": 500 } }</code></p>              |
| {% endtab %}                         |                                                                                                                                       |

{% tab title="Changelog" %}

## Changelog

### \[3.0.0] - 2025-07-17

### \[Breaking] Major refactoring - restructured parameters into Input, Connection, and Options classes with improved error handling

#### Breaking Changes

* **Parameter Structure Reorganization**: Task parameters have been restructured into three main classes:
  * **Input**: Contains core task parameters (BucketName, SourceDirectory, SearchPattern, DownloadFromCurrentDirectoryOnly, TargetDirectory)
  * **Connection**: Contains connection-related parameters (AwsCredentials, PreSignedUrl)
  * **Options**: Contains optional configuration parameters (FileLockedRetries, DeleteSourceObject, ThrowErrorIfNoMatch, ActionOnExistingFile, ThrowErrorOnFailure, ErrorMessageOnFailure)

#### Parameter Changes

* **Moved to Input tab**:
  * `Connection.BucketName` → `Input.BucketName`
  * `Connection.S3Directory` → `Input.SourceDirectory` (renamed)
  * `Connection.SearchPattern` → `Input.SearchPattern`
  * `Connection.DownloadFromCurrentDirectoryOnly` → `Input.DownloadFromCurrentDirectoryOnly`
  * `Connection.DestinationDirectory` → `Input.TargetDirectory` (renamed)
* **Moved to Options tab**:
  * `Connection.FileLockedRetries` → `Options.FileLockedRetries`
  * `Connection.DeleteSourceObject` → `Options.DeleteSourceObject`
  * `Connection.ThrowErrorIfNoMatch` → `Options.ThrowErrorIfNoMatch`
  * `Connection.DestinationFileExistsAction` → `Options.ActionOnExistingFile` (renamed)
* **Updated in Connection tab**:
  * `Connection.AWSCredentials` → `Connection.AwsCredentials` (renamed)
  * `Connection.PreSignedURL` → `Connection.PreSignedUrl` (renamed)

#### New Features

* **Enhanced Error Handling**: Added comprehensive error handling with new Options properties:
  * `ThrowErrorOnFailure` (bool, default: false) – Controls whether errors throw exceptions
  * `ErrorMessageOnFailure` (string, default: "") - Custom error message for failures
* **Improved Result Structure**:
  * Renamed `Data` property to `Objects` in Result class
  * Added structured `Error` property with `Message` and `AdditionalInfo` fields

### \[2.2.0] - 2024-12-11

#### Updated

* Listing updated to newer version.

### \[2.1.0] - 2023-05-10

#### Fixed

* Changed the way the Task handles downloaded objects to fix blank PDF files.

#### Changed

* Result change: List name change from 'Results' to 'Data'.
* Input parameter name changed from to 'Connection'.
* Memory leak fix.
* SingleResultObject parameter changes:
  * New parameters: Overwritten, SourceDeleted, Info.
  * Removed parameter: ObjectData (replaced by Info).

### \[2.0.0] - 2022-12-02

#### Modified

* Memory leak fix.
* SingleResultObject parameter changes:
  * New parameters: Overwritten, SourceDeleted, Info.
  * Removed parameter: ObjectData (replaced by Info).

### \[1.0.0] - 2022-05-09

#### Added

* Initial implementation
  {% endtab %}
  {% endtabs %}
