<BlockSwitcher>

<Block name="Async/Await">

```swift
func downloadData(key: String, identityId: String) async throws {
    let options = StorageDownloadDataRequest.Options(
        accessLevel: .protected,
        targetIdentityId: identityId
    )

    let downloadTask = Amplify.Storage.downloadData(
        key: key,
        options: options
    )

    Task {
        for await progress in await downloadTask.progress {
            print("Progress: \(progress)")
        }
    }
    let data = try await downloadTask.value
    print("Completed: \(data)")
}

```

</Block>

<Block name="Combine">

```swift
var progressSink: AnyCancellable?
var resultSink: AnyCancellable?

func downloadData(key: String, identityId: String) {
    let options = StorageDownloadDataRequest.Options(
        accessLevel: .protected,
        targetIdentityId: identityId
    )
    let downloadTask = Amplify.Storage.downloadData(
        key: key,
        options: options
    )
    progressSink = downloadTask
        .inProcessPublisher
        .sink { progress in
            print("Progress: \(progress)")
        }

    resultSink = downloadTask
        .resultPublisher
        .sink {
            if case let .failure(storageError) = $0 {
                print("Failed: \(storageError.errorDescription). \(storageError.recoverySuggestion)")
            }
        }
        receiveValue: { data in
            print("Completed: \(data)")
        }
}
```

</Block>

</BlockSwitcher>
