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

# Attachments

> 說明如何在 Laravel Copilot SDK 中附加檔案、目錄、選取範圍、Blob 並送出 prompt。

## 檔案附件

以下方式將檔案或目錄以陣列指定。

```php theme={null}
use Revolution\Copilot\Facades\Copilot;

$attachments = [
    [
        'type' => 'file',
        'path' => '/path/to/file.php',
        'displayName' => 'My File',// 可省略
    ],
    [
        'type' => 'directory',
        'path' => '/path/to/dir/',
        'displayName' => 'dir',// 可省略
    ],
    [
        'type' => 'selection',
        'filePath' => '/path/to/file.php',
        'displayName' => 'My File',// 此處不可省略
        'selection' => [
            'start' => ['line' => 1, 'character' => 10],
            'end' => ['line' => 5, 'character' => 10],
        ],
        'text' => '...',
    ],
    [
        'type' => 'blob',
        'data' => base64_encode(file_get_contents('/path/to/image.png')),
        'mimeType' => 'image/png',
        'displayName' => 'screenshot.png',// 可省略
    ],
];

$response = Copilot::run(prompt: '...', attachments: $attachments);
```

由於這種格式難以記憶，故提供了輔助工具讓使用更方便。

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Support\Attachment;

$attachments = [
    Attachment::file(path: '/path/to/file.php', displayName: 'My File'),
    Attachment::directory(path: '/path/to/dir/', displayName: 'dir'),
    Attachment::selection(filePath: '/path/to/file.php', displayName: 'My File', selection: ['start' => ['line' => 1, 'character' => 10], 'end' => ['line' => 5, 'character' => 10]], text: '...'),
    Attachment::blob(data: base64_encode(file_get_contents('/path/to/image.png')), mimeType: 'image/png', displayName: 'screenshot.png'),
];

$response = Copilot::run(prompt: '...', attachments: $attachments);
```

## Blob 附件

`blob` 類型用於將 Base64 編碼的資料以 inline 方式附加。可以在不做磁碟 I/O 的情況下直接傳送圖像等二進位資料。

```php theme={null}
use Revolution\Copilot\Support\Attachment;

// 將圖像檔以 Base64 編碼後附加
$attachment = Attachment::blob(
    data: base64_encode(file_get_contents('/path/to/image.png')),
    mimeType: 'image/png',
    displayName: 'screenshot.png',
);
```

<Info>
  `selection` 在官方 SDK 尚無文件，因此細節不明。`github_reference` 也因官方資訊不足，將於後續支援。
</Info>

<Info>
  最新資訊請參考 [GitHub 儲存庫](https://github.com/invokable/laravel-copilot-sdk)。
</Info>


## Related topics

- [郵件寄送](/zh-TW/mail.md)
- [Laravel Notification for Discord(Webhook)](/zh-TW/packages/laravel-notification-discord-webhook.md)
- [Streaming Events](/zh-TW/packages/laravel-copilot-sdk/streaming-events.md)
- [Laravel AI SDK](/zh-TW/ai-sdk.md)
- [Laravel AI SDK 的 Amazon Bedrock 驅動](/zh-TW/packages/laravel-amazon-bedrock.md)
