|
| 1 | +# Attachments Service |
| 2 | + |
| 3 | +The `AttachmentsService` provides methods to upload, download, and delete attachments in UiPath Orchestrator. Attachments are files that can be associated with jobs, processes, or other entities, and are managed via the Orchestrator API. |
| 4 | + |
| 5 | +> **Reference:** [UiPath Orchestrator Attachments API](https://docs.uipath.com/orchestrator/reference/api-attachments) |
| 6 | +
|
| 7 | +## Features |
| 8 | +- Upload files or in-memory content as attachments |
| 9 | +- Download attachments to local files |
| 10 | +- Delete attachments |
| 11 | +- Both synchronous and asynchronous methods |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Instantiating the Service |
| 16 | + |
| 17 | +The `AttachmentsService` is available as a property on the main `UiPath` client: |
| 18 | + |
| 19 | +```python |
| 20 | +from uipath import UiPath |
| 21 | + |
| 22 | +client = UiPath() |
| 23 | +attachments = client.attachments |
| 24 | +``` |
| 25 | + |
| 26 | +### Uploading an Attachment |
| 27 | + |
| 28 | +You can upload a file from disk or from memory: |
| 29 | + |
| 30 | +```python |
| 31 | +# Upload from file |
| 32 | +attachment_key = client.attachments.upload( |
| 33 | + name="document.pdf", |
| 34 | + source_path="/path/to/document.pdf", |
| 35 | +) |
| 36 | + |
| 37 | +# Upload from memory |
| 38 | +attachment_key = client.attachments.upload( |
| 39 | + name="notes.txt", |
| 40 | + content="Some text content", |
| 41 | +) |
| 42 | +``` |
| 43 | + |
| 44 | +#### Async Example |
| 45 | +```python |
| 46 | +attachment_key = await client.attachments.upload_async( |
| 47 | + name="notes.txt", |
| 48 | + content="Some text content", |
| 49 | +) |
| 50 | +``` |
| 51 | + |
| 52 | +### Downloading an Attachment |
| 53 | + |
| 54 | +```python |
| 55 | +attachment_name = client.attachments.download( |
| 56 | + key=attachment_key, |
| 57 | + destination_path="/path/to/save/document.pdf", |
| 58 | +) |
| 59 | +``` |
| 60 | + |
| 61 | +#### Async Example |
| 62 | +```python |
| 63 | +attachment_name = await client.attachments.download_async( |
| 64 | + key=attachment_key, |
| 65 | + destination_path="/path/to/save/document.pdf", |
| 66 | +) |
| 67 | +``` |
| 68 | + |
| 69 | +### Deleting an Attachment |
| 70 | + |
| 71 | +```python |
| 72 | +client.attachments.delete(key=attachment_key) |
| 73 | +``` |
| 74 | + |
| 75 | +#### Async Example |
| 76 | +```python |
| 77 | +await client.attachments.delete_async(key=attachment_key) |
| 78 | +``` |
| 79 | + |
| 80 | +## Error Handling |
| 81 | + |
| 82 | +All methods raise exceptions on failure. See the SDK error handling documentation for details. |
| 83 | + |
| 84 | +## See Also |
| 85 | +- [UiPath Orchestrator Attachments API](https://docs.uipath.com/orchestrator/reference/api-attachments) |
| 86 | +- [Jobs Service](./jobs.md) for listing attachments associated with jobs. |
0 commit comments