# Download an artifact

List the files a run uploaded and download one before it expires.

A run uploads artifacts with an `artifact` step in the native format (see
[Workflow syntax](/docs/workflows)) or with `actions/upload-artifact` (v4 and later) in a
GitHub-syntax workflow. An artifact can be downloaded for the days the workflow asks for, 1 to 90,
and 30 when it does not say.

Replace run-id with the run's id, artifact-id with the artifact's id and
artifact-file with the file to save it to.

## Prerequisites

- `ci:ListArtifacts` on the run's repository (`rn:ews::<organization id>:ci:repository/<repository id>`)
  to list them.
- `ci:DownloadArtifact` on it to download one. It is marked sensitive: the read-only policies do
  not include it, and a refused download is recorded in the audit log.
- In the console, also `git:GetRepository`, `ci:ListRuns` and `ci:GetRun` on the repository to
  open the run; without them the page is not found.

## Download it

**Console**
1. Open the repository, then open its **CI** tab.
2. Open the run.
3. Under **Artifacts**, choose **Download** next to the artifact. The section appears once the run
   has uploaded an artifact.

An expired artifact reads **Expired**; without `ci:DownloadArtifact` the row reads **No access**.

**CLI**
```sh
dcloud ci artifacts list run-id
dcloud ci artifacts download artifact-id > artifact-file
```

`download` writes the artifact's raw bytes to standard output, so redirect it to a file.

**API**
```http
GET /ci/api/runs/run-id/artifacts
```

```http
GET /ci/api/artifacts/artifact-id/download
```

The list gives each artifact's `id`, `name`, `sizeBytes`, `expiresAt` and `createdAt`. The download
answers `302` to a storage link valid for five minutes.

## Result

You have the artifact's file.

- `410` "This artifact has expired" once it is past `expiresAt`.
- `404` when the run or the artifact is not in your organization.

## Related

- [Watch a run](watch-a-run.md)
- `ci.artifacts.download` · `dcloud ci artifacts download`
