# Generate URL to download a file

# Overview
This API prepares the download of a file, such as an activity attachment, article attachment, or inline image.
It returns a short-lived signed URL that can be used to download the file bytes.
This is step 1 of a 2-step download flow:
1. **Call this API**
 with the application context and
`fileId`
. The response includes

a signed
`downloadUrl`
 and file metadata.
2. **Download the file bytes**
 from the
`downloadUrl`
 (see below).

`fileId` is the stable numeric attachment ID of a file that is already linked to an article or activity,
or an article's inline image ID.
## Downloading the file bytes
To complete the download, the client must:
* Send a
`GET`
 request to the
`downloadUrl`
 returned in this API response.
* No additional authentication is required; the URL signature authorizes the request.

The `downloadUrl` is valid for 30 minutes.
On success, the server returns `200` with the file bytes in the response body.
If the URL has expired or is invalid, the request fails with an error.
# Permissions
There is no permission on the attachment itself. Access is evaluated against the file's
owning resource, identified by the request body parameter `application`.
If the file does not exist or is not linked to a resource, the API returns `400`.
If the caller is not allowed to access the owning resource, the API returns `403`.
Requirements vary by Actor and by `application` value:
| Actor | Permission |
|  --- | --- |
| OAuthUser, OAuthOnBehalfOfUser | `article`: The user must have `View Folder` permission on the article's parent folder. For a suggestion, the user must either be the creator or be allowed to work on it through the article approval process.`email`, `task`, `calltrack`: The user must be allowed to access the owning activity of the requested file, same as [Get activity attachment details](../apis/v3/core/casemgr/api-bundled/activity/getactivityattachmentdetails). |
| OAuthCustomer, OAuthOnBehalfOfCustomer | `article`: The customer must be allowed to access the owning article or suggestion.`email`, `task`, `calltrack`: The customer must be allowed to access the owning activity of the requested file, same as [Get activity attachment details](../apis/v3/core/casemgr/api-bundled/activity/getactivityattachmentdetails). |
| OAuthAnonymousCustomer | `article`:The owning article must be viewable by anonymous customers.If the file is linked to a suggestion, no access is allowed.`email`, `task`, `calltrack`: Not allowed. |
| OAuthClient | `article`: Not allowed.`email`, `task`, `calltrack`: No additional permission is required. |

Endpoint: POST /assets/predownload
Security: oAuthUser, oAuthOnBehalfOfUser, oAuthCustomer, oAuthOnBehalfOfCustomer, oAuthAnonymousCustomer, oAuthClient

## Description:

  - `Overview` ()
    This API prepares the download of a file, such as an activity attachment, article attachment, or inline image.
It returns a short-lived signed URL that can be used to download the file bytes. This is step 1 of a 2-step download flow: 1. **Call this API**
 with the application context and
`fileId`
. The response includes

a signed
`downloadUrl`
 and file metadata.
2. **Download the file bytes**
 from the
`downloadUrl`
 (see below). `fileId` is the stable numeric attachment ID of a file that is already linked to an article or activity,
or an article's inline image ID.

  - `Downloading the file bytes` ()
    To complete the download, the client must: * Send a
`GET`
 request to the
`downloadUrl`
 returned in this API response.
* No additional authentication is required; the URL signature authorizes the request. The `downloadUrl` is valid for 30 minutes. On success, the server returns `200` with the file bytes in the response body.
If the URL has expired or is invalid, the request fails with an error.

  - `Permissions` ()
    There is no permission on the attachment itself. Access is evaluated against the file's
owning resource, identified by the request body parameter `application`.
If the file does not exist or is not linked to a resource, the API returns `400`.
If the caller is not allowed to access the owning resource, the API returns `403`. Requirements vary by Actor and by `application` value: | Actor | Permission |
|  --- | --- |
| OAuthUser, OAuthOnBehalfOfUser | `article`: The user must have `View Folder` permission on the article's parent folder. For a suggestion, the user must either be the creator or be allowed to work on it through the article approval process.`email`, `task`, `calltrack`: The user must be allowed to access the owning activity of the requested file, same as [Get activity attachment details](../apis/v3/core/casemgr/api-bundled/activity/getactivityattachmentdetails). |
| OAuthCustomer, OAuthOnBehalfOfCustomer | `article`: The customer must be allowed to access the owning article or suggestion.`email`, `task`, `calltrack`: The customer must be allowed to access the owning activity of the requested file, same as [Get activity attachment details](../apis/v3/core/casemgr/api-bundled/activity/getactivityattachmentdetails). |
| OAuthAnonymousCustomer | `article`:The owning article must be viewable by anonymous customers.If the file is linked to a suggestion, no access is allowed.`email`, `task`, `calltrack`: Not allowed. |
| OAuthClient | `article`: Not allowed.`email`, `task`, `calltrack`: No additional permission is required. |

## Security:

  - `oAuthUser` (unknown)
    oauth2 scopes: https://api.egain.cloud/auth/core.filemgr.read

  - `oAuthOnBehalfOfUser` (unknown)
    oauth2 scopes: https://api.egain.cloud/auth/core.filemgr.onbehalfof.read

  - `oAuthCustomer` (unknown)
    oauth2 scopes: https://api.egain.cloud/auth/core.filemgr.read

  - `oAuthOnBehalfOfCustomer` (unknown)
    oauth2 scopes: https://api.egain.cloud/auth/core.filemgr.onbehalfof.read

  - `oAuthAnonymousCustomer` (unknown)
    oauth2 scopes: https://api.egain.cloud/auth/core.filemgr.read

  - `oAuthClient` (unknown)
    oauth2 scopes: https://api.egain.cloud/auth/.default

## Header parameters:

  - `Accept` (string, required)
    The content type accepted by the client.

  - `Content-Type` (string, required)
    The media type sent by the client.

  - `Accept-Language` (string, required)
    The Language locale accepted by the client (used for locale specific fields in resource representation and in error responses).

## Request fields (application/json):

  - `application` (string, required)
    eGain application that owns the file. `article` for article attachments or inline images.
`email`, `task`, or `calltrack` for activity attachments.
    Enum: "article", "email", "task", "calltrack"

  - `fileId` (string, required)
    The identifier of a file that is already associated with an article or activity and returned by the application
that owns the file.
Format depends on `application` and the type of attachment:
- `article`
 attachments: The numeric attachment ID. It can be obtained from the

[Get An Article By Id With Content](../apis/v4/knowledge/contentmgr/api-bundled/articles/getarticlewithcontent)

API response.
- `article`
 inline images: The stored image id from article HTML (
`id`
 on GET v4, or the

path segment in v20
`src="/system/ws/v11/media/image/{id}"`
). Classic ids are

`{prefix}/{uuid}`
 (on-prem 4-digit year, 14-character tenant, or Rigel
`TM…`
 prefix).

Legacy bare UUIDs remain valid. Example:

`<img id="2024/96ea5bd9-36dd-4771-aaa7-aa8cf794307e" src="https://api.egain.cloud/core/filemgr/v4/assets/download?signature=35674B764E7848586E786..." />`
.
- `email`
,
`task`
, and
`calltrack`
 attachments: The numeric attachment ID of the linked activity attachment.

It can be obtained from:
  - [Get activity attachments](../apis/v3/core/casemgr/api-bundled/activity/getactivityattachments)
  - [Get activity attachment details](../apis/v3/core/casemgr/api-bundled/activity/getactivityattachmentdetails)

Do not use `fileUploadId` or `altId`.
Files that have been uploaded but not yet associated with an article or activity cannot
be downloaded.

  - `articleId` (string)
    The ID of the article that owns this file. Required only when `application` is `article`.

## Request examples:

  - `Predownload article attachment` (unknown)

  - `Predownload article inline image` (unknown)

  - `Predownload email attachment` (unknown)

  - `Predownload task attachment` (unknown)

  - `Predownload calltrack attachment` (unknown)

## Response 200:

  - `200` (unknown)
    Success

## Response 200 fields (application/json):

  - `fileId` (string, required)
    The application-specific identifier for this file.
This is the same `fileId` sent by the client in the request.

  - `fileName` (string, required)
    File name including the file extension.

  - `mediaType` (string, required)
    Media type (MIME type) of the file, for example `image/png`.

  - `size` (integer, required)
    File size in bytes.

  - `downloadUrl` (string, required)
    Signed URL to download file bytes. Send a `GET` request to this URL. This URL is valid for 30 minutes.

## Response 400:

  - `400` (unknown)
    Bad Request

## Response 400 fields (application/json):

  - `code` (string, required)
    A string that follows the pattern *{integer}-{integer}*.
The first *{integer}* is the http status code.  This code as a whole is unique.
* For example, error codes "400-101" and "404-101" are distinctly different.

  - `developerMessage` (string, required)
    A summary of the error.

  - `details` (array)

  - `details.key` (string, required)

  - `details.value` (string)

  - `userMessage` (string)
    UI friendly messages are only supported by some APIs.
* The client must explicitly request UI friendly messages by passing the
*X-egain-error-message=yes*
 header.

## Response 401:

  - `401` (unknown)
    Unauthorized

## Response 401 fields (application/json):

  - `code` (string, required)
    A string that follows the pattern *{integer}-{integer}*.
The first *{integer}* is the http status code.  This code as a whole is unique.
* For example, error codes "400-101" and "404-101" are distinctly different.

  - `developerMessage` (string, required)
    A summary of the error.

  - `details` (array)

  - `details.key` (string, required)

  - `details.value` (string)

  - `userMessage` (string)
    UI friendly messages are only supported by some APIs.
* The client must explicitly request UI friendly messages by passing the
*X-egain-error-message=yes*
 header.

## Response 403:

  - `403` (unknown)
    Forbidden

## Response 403 fields (application/json):

  - `code` (string, required)
    A string that follows the pattern *{integer}-{integer}*.
The first *{integer}* is the http status code.  This code as a whole is unique.
* For example, error codes "400-101" and "404-101" are distinctly different.

  - `developerMessage` (string, required)
    A summary of the error.

  - `details` (array)

  - `details.key` (string, required)

  - `details.value` (string)

  - `userMessage` (string)
    UI friendly messages are only supported by some APIs.
* The client must explicitly request UI friendly messages by passing the
*X-egain-error-message=yes*
 header.

## Response 406:

  - `406` (unknown)
    Not Acceptable

## Response 406 fields (application/json):

  - `code` (string, required)
    A string that follows the pattern *{integer}-{integer}*.
The first *{integer}* is the http status code.  This code as a whole is unique.
* For example, error codes "400-101" and "404-101" are distinctly different.

  - `developerMessage` (string, required)
    A summary of the error.

  - `details` (array)

  - `details.key` (string, required)

  - `details.value` (string)

  - `userMessage` (string)
    UI friendly messages are only supported by some APIs.
* The client must explicitly request UI friendly messages by passing the
*X-egain-error-message=yes*
 header.

## Response 429:

  - `429` (unknown)
    Too Many Request

## Response 429 fields (application/json):

  - `code` (string, required)
    A string that follows the pattern *{integer}-{integer}*.
The first *{integer}* is the http status code.  This code as a whole is unique.
* For example, error codes "400-101" and "404-101" are distinctly different.

  - `developerMessage` (string, required)
    A summary of the error.

  - `details` (array)

  - `details.key` (string, required)

  - `details.value` (string)

  - `userMessage` (string)
    UI friendly messages are only supported by some APIs.
* The client must explicitly request UI friendly messages by passing the
*X-egain-error-message=yes*
 header.

## Response 500:

  - `500` (unknown)
    Internal server error

## Response 500 fields (application/json):

  - `code` (string, required)
    A string that follows the pattern *{integer}-{integer}*.
The first *{integer}* is the http status code.  This code as a whole is unique.
* For example, error codes "400-101" and "404-101" are distinctly different.

  - `developerMessage` (string, required)
    A summary of the error.

  - `details` (array)

  - `details.key` (string, required)

  - `details.value` (string)

  - `userMessage` (string)
    UI friendly messages are only supported by some APIs.
* The client must explicitly request UI friendly messages by passing the
*X-egain-error-message=yes*
 header.

## Response 200 examples:

  - `Predownload article attachment response` (unknown)

  - `Predownload article inline image response` (unknown)

## Response 400 examples:

  - `Unsupported Parameters` (unknown)

  - `Invalid Value` (unknown)

  - `Missing required query parameter` (unknown)

## Response 401 examples:

  - `Unauthorized` (unknown)

## Response 403 examples:

  - `Forbidden` (unknown)

## Response 406 examples:

  - `Invalid Accept-Language` (unknown)

## Response 429 examples:

  - `Too Many Request` (unknown)
    Too many requests. Try again at a later time.

## Response 500 examples:

  - `Internal Server Error` (unknown)

