or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

attachments.mdcli.mdcomments.mdcore-api.mdenterprise.mdformulas.mdindex.mdorm.mdrecord-operations.mdtesting.mdwebhooks.md

attachments.mddocs/

0

# Attachment Management

1

2

File upload and attachment management with support for multiple attachment fields, content type detection, and URL-based attachments.

3

4

## Capabilities

5

6

### File Upload

7

8

Upload files directly to Airtable attachment fields with automatic content type detection and metadata handling.

9

10

```python { .api }

11

def upload_attachment(self, record_id: str, field: str, filename: str,

12

content: Optional[bytes] = None,

13

content_type: Optional[str] = None) -> dict:

14

"""

15

Upload file to attachment field.

16

17

Parameters:

18

- record_id: Record ID to add attachment to

19

- field: Attachment field name or ID

20

- filename: File path or name for the attachment

21

- content: File content as bytes (reads from filename if None)

22

- content_type: MIME type (auto-detected if None)

23

24

Returns:

25

Dict with complete attachment field value including new attachment

26

"""

27

```

28

29

### Usage Examples

30

31

```python

32

from pyairtable import Api

33

34

api = Api('your_token')

35

table = api.table('base_id', 'table_name')

36

37

# Upload file from disk

38

result = table.upload_attachment(

39

'rec1234567890abcde',

40

'Attachments',

41

'/path/to/document.pdf'

42

)

43

44

# Upload from memory with custom content type

45

with open('/path/to/image.jpg', 'rb') as f:

46

content = f.read()

47

48

result = table.upload_attachment(

49

'rec1234567890abcde',

50

'Photos',

51

'custom_name.jpg',

52

content=content,

53

content_type='image/jpeg'

54

)

55

56

# URL-based attachments (create record with attachment URLs)

57

record = table.create({

58

'Name': 'Document Record',

59

'Files': [

60

{'url': 'https://example.com/doc.pdf', 'filename': 'document.pdf'},

61

{'url': 'https://example.com/img.png'} # filename auto-detected

62

]

63

})

64

```