> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Download File

> **Available for**: Chatflow, Chatbot, Agent, Text Generator apps.

Preview or download uploaded files previously uploaded via the [Upload File](/en/api-reference/files/upload-file) API. Files can only be accessed if they belong to messages within the requesting application.



## OpenAPI

````yaml /en/api-reference/openapi_service.json get /files/{file_id}/preview
openapi: 3.0.1
info:
  title: Dify Service API
  description: >-
    REST API for Dify applications and knowledge bases. Application endpoints
    authenticate with an app API key; knowledge endpoints authenticate with a
    dataset API key.
  version: 1.0.0
servers:
  - url: https://{api_base_url}
    description: >-
      Base URL of the Dify Service API. For self-hosted deployments, replace it
      with your own API base URL.
    variables:
      api_base_url:
        default: api.dify.ai/v1
        description: Host and path of the API base URL, without the `https://` prefix.
security:
  - ApiKeyAuth: []
tags:
  - name: Chat Messages
    description: Operations related to chat messages and interactions.
  - name: Files
    description: File upload and preview operations.
  - name: End Users
    description: Operations related to end user information.
  - name: Feedback
    description: User feedback operations.
  - name: Conversations
    description: Operations related to managing conversations.
  - name: Audio
    description: Text-to-Speech and Speech-to-Text operations.
  - name: Applications
    description: Operations to retrieve application settings and information.
  - name: Annotations
    description: Operations related to managing annotations for direct replies.
  - name: Human Input
    description: Endpoints for resuming paused workflows that require human input.
  - name: Workflow Runs
    description: Operations for executing and managing workflows.
  - name: Completion Messages
    description: Operations related to text generation and completion.
  - name: Knowledge Bases
    description: >-
      Operations for managing knowledge bases, including creation,
      configuration, and retrieval.
  - name: Documents
    description: >-
      Operations for creating, updating, and managing documents within a
      knowledge base.
  - name: Chunks
    description: Operations for managing document chunks and child chunks.
  - name: Metadata
    description: >-
      Operations for managing knowledge base metadata fields and document
      metadata values.
  - name: Tags
    description: Operations for managing knowledge base tags and tag bindings.
  - name: Models
    description: Operations for retrieving available models.
  - name: Knowledge Pipeline
    description: >-
      Operations for managing and running knowledge pipelines, including
      datasource plugins and pipeline execution.
paths:
  /files/{file_id}/preview:
    get:
      tags:
        - Files
      summary: Download File
      description: >-
        **Available for**: Chatflow, Chatbot, Agent, Text Generator apps.


        Preview or download uploaded files previously uploaded via the [Upload
        File](/en/api-reference/files/upload-file) API. Files can only be
        accessed if they belong to messages within the requesting application.
      operationId: previewChatFile
      parameters:
        - name: file_id
          in: path
          required: true
          description: >-
            The unique identifier of the file to preview, obtained from the
            [Upload File](/en/api-reference/files/upload-file) API response.
          schema:
            type: string
            format: uuid
        - name: as_attachment
          in: query
          required: false
          description: >-
            If `true`, forces the file to download as an attachment instead of
            previewing in browser.
          schema:
            type: boolean
            default: false
        - name: user
          in: query
          required: false
          description: User identifier, used for end-user context.
          schema:
            type: string
      responses:
        '200':
          description: >-
            Returns the raw file content. The `Content-Type` header is set to
            the file's MIME type. If `as_attachment` is `true`, the file is
            returned as a download with `Content-Disposition: attachment`.
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
        '403':
          description: '`file_access_denied` : Access to the requested file is denied.'
          content:
            application/json:
              examples:
                file_access_denied:
                  summary: file_access_denied
                  value:
                    status: 403
                    code: file_access_denied
                    message: Access to the requested file is denied.
        '404':
          description: '`file_not_found` : The requested file was not found.'
          content:
            application/json:
              examples:
                file_not_found:
                  summary: file_not_found
                  value:
                    status: 404
                    code: file_not_found
                    message: The requested file was not found.
components:
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API_KEY
      description: >-
        API Key authentication. For all API requests, include your API Key in
        the `Authorization` HTTP Header, prefixed with `Bearer `. Example:
        `Authorization: Bearer {API_KEY}`. **Strongly recommend storing your API
        Key on the server-side, not shared or stored on the client-side, to
        avoid possible API-Key leakage that can lead to serious consequences.**
        Requests with a missing or invalid API key fail with HTTP `401` and
        error code `unauthorized`.

````