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

# Training Files

> Access downloadable files associated with learning paths for supplementary learning materials

Training Files provide learners with additional downloadable resources that supplement their learning experience. These files are directly associated with specific learning paths and are accessible to enrolled users.

## Overview

Training Files are media entities that can be attached to learning paths to provide:

* **Supplementary Materials**: PDFs, documents, presentations, and other resources
* **Reference Documents**: Additional reading materials and guides
* **Media Content**: Images, videos, and multimedia files
* **Templates**: Downloadable templates and worksheets

## Supported File Types

The system supports a wide range of file formats organized by logical file types:

| File Type      | Extensions                          | Description                                         |
| -------------- | ----------------------------------- | --------------------------------------------------- |
| **PDF**        | `pdf`                               | Portable Document Format files                      |
| **Text**       | `txt`                               | Plain text documents                                |
| **Word**       | `doc`, `docx`, `odt`                | Microsoft Word and OpenDocument text documents      |
| **Excel**      | `xls`, `xlsx`, `ods`                | Microsoft Excel and OpenDocument spreadsheets       |
| **PowerPoint** | `ppt`, `pptx`, `pps`, `ppsx`, `odp` | Microsoft PowerPoint and OpenDocument presentations |
| **Image**      | `png`, `jpeg`, `jpg`, `gif`         | Common image formats                                |
| **Video**      | `mp4`                               | MP4 video files                                     |

<Note>
  Maximum file size is **500 MB** per file. Files are stored in the `training-files` directory.
</Note>

## GraphQL Query

Training files are accessed through the `trainingFiles` field on the `LearningPath` type:

<CodeGroup>
  ```graphql Get Training Files theme={null}
  query getLearningPath {
    getLearningPath(lpId: "40") {
      trainingFiles {
        id
        name
        description
        filename
        url
        mimeType
        size
        extension
      }
    }
  }
  ```

  ```json Response Example theme={null}
  {
    "data": {
      "getLearningPath": {
        "trainingFiles": [
          {
            "id": "123",
            "name": "Course Handbook",
            "description": "Complete guide for the learning path",
            "filename": "course-handbook.pdf",
            "url": "https://example.com/sites/default/files/training-files/course-handbook.pdf",
            "mimeType": "application/pdf",
            "size": 2048576,
            "extension": "pdf"
          },
          {
            "id": "124",
            "name": "Exercise Template",
            "description": "Template for practical exercises",
            "filename": "exercise-template.docx",
            "url": "https://example.com/sites/default/files/training-files/exercise-template.docx",
            "mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "size": 524288,
            "extension": "docx"
          }
        ]
      }
    }
  }
  ```
</CodeGroup>

## TrainingFile Fields

| Field         | Type      | Description                                                        |
| ------------- | --------- | ------------------------------------------------------------------ |
| `id`          | `ID!`     | Unique identifier of the training file                             |
| `name`        | `String`  | Display name of the file (customizable title)                      |
| `description` | `String`  | Optional description explaining the file's purpose                 |
| `filename`    | `String!` | Original filename of the uploaded file                             |
| `url`         | `String!` | Secure download URL with JWT token for authentication              |
| `mimeType`    | `String!` | MIME type of the file (e.g., `application/pdf`)                    |
| `size`        | `Int!`    | File size in bytes                                                 |
| `extension`   | `String`  | File extension (e.g., `pdf`, `docx`) - used to determine file type |

## Access Control

<Warning>
  Training files are subject to strict access control:

  * **User Authentication**: Must be authenticated with valid user context
  * **Learning Path Access**: User must have access to the associated learning path
  * **Enrollment Status**: Typically requires enrollment in the learning path
</Warning>

## Secure Download URLs

The `url` field returns a secure download link that includes a JWT token for authentication. The system generates these URLs dynamically:

<Steps>
  <Step title="JWT Token Generation">
    Creates a secure token containing:

    * Media ID (training file)
    * Learning Path ID
    * User Context UUID
  </Step>

  <Step title="URL Construction">
    Builds URL in format: `/training-files/secure/{token}`
  </Step>

  <Step title="Access Validation">
    When accessed, the system validates:

    * Token authenticity and expiration
    * User access to the learning path
    * File existence and availability
  </Step>
</Steps>

<Info>
  **Token Security**: Each download URL contains a unique JWT token that expires and is tied to the specific user, learning path, and file combination. This prevents unauthorized access and link sharing.
</Info>

## Related Operations

<CardGroup cols={2}>
  <Card title="Learning Path" icon="route" href="/OpignoEnterpriseAPI/LearningPath">
    Learn about the complete learning path structure and navigation
  </Card>

  <Card title="Learning Path Homepage" icon="house" href="/OpignoEnterpriseAPI/LearningPathHomepage">
    Understand how to build learning path interfaces with all available data
  </Card>
</CardGroup>
