0
# File Operations
1
2
Upload, download, manage, and share files within Slack channels and conversations.
3
4
## Capabilities
5
6
### File Management
7
8
Upload and manage files within your Slack workspace.
9
10
```python { .api }
11
def upload(self, file_=None, content=None, filetype=None, filename=None, title=None, initial_comment=None, channels=None, thread_ts=None):
12
"""
13
Upload a file to Slack.
14
15
Args:
16
file_ (str or file object, optional): File path or file object to upload
17
content (str, optional): File content as string (for text files)
18
filetype (str, optional): File type identifier
19
filename (str, optional): Filename for the upload
20
title (str, optional): Title for the file
21
initial_comment (str, optional): Initial comment on the file
22
channels (list of str, optional): Channels to share file in
23
thread_ts (str, optional): Thread timestamp for threaded file sharing
24
25
Returns:
26
Response: Uploaded file information including file ID and URL
27
"""
28
29
def delete(self, file_):
30
"""
31
Delete a file.
32
33
Args:
34
file_ (str): File ID to delete
35
36
Returns:
37
Response: Deletion confirmation
38
"""
39
40
def info(self, file_, count=None, page=None):
41
"""
42
Get information about a file.
43
44
Args:
45
file_ (str): File ID
46
count (int, optional): Number of comments to return
47
page (int, optional): Page of comments to return
48
49
Returns:
50
Response: File information including metadata and comments
51
"""
52
53
def list(self, user=None, ts_from=None, ts_to=None, types=None, count=None, page=None, channel=None):
54
"""
55
List files in workspace.
56
57
Args:
58
user (str, optional): Filter by user ID
59
ts_from (str, optional): Filter files after timestamp
60
ts_to (str, optional): Filter files before timestamp
61
types (str, optional): Filter by file types (comma-separated)
62
count (int, optional): Number of files per page
63
page (int, optional): Page number
64
channel (str, optional): Filter by channel
65
66
Returns:
67
Response: List of files with metadata
68
"""
69
```
70
71
Usage:
72
```python
73
# Upload file from path
74
slack.files.upload('/path/to/file.txt', channels=['#general'])
75
76
# Upload file content directly
77
slack.files.upload(content='Hello, world!', filename='greeting.txt', channels=['#general'])
78
79
# Upload with file object
80
with open('/path/to/file.pdf', 'rb') as f:
81
slack.files.upload(file_=f, title='Important Document', channels=['#documents'])
82
```
83
84
### File Sharing
85
86
Manage file sharing and public access.
87
88
```python { .api }
89
def shared_public_url(self, file_):
90
"""
91
Create a public URL for a file.
92
93
Args:
94
file_ (str): File ID
95
96
Returns:
97
Response: Public URL information
98
"""
99
100
def revoke_public_url(self, file_):
101
"""
102
Revoke public URL access for a file.
103
104
Args:
105
file_ (str): File ID
106
107
Returns:
108
Response: Revocation confirmation
109
"""
110
```
111
112
### File Comments
113
114
Add, edit, and manage comments on files.
115
116
```python { .api }
117
def add(self, file_, comment):
118
"""
119
Add a comment to a file.
120
121
Args:
122
file_ (str): File ID
123
comment (str): Comment text
124
125
Returns:
126
Response: Created comment information
127
"""
128
129
def edit(self, file_, id_, comment):
130
"""
131
Edit an existing comment on a file.
132
133
Args:
134
file_ (str): File ID
135
id_ (str): Comment ID
136
comment (str): New comment text
137
138
Returns:
139
Response: Updated comment information
140
"""
141
142
def delete(self, file_, id_):
143
"""
144
Delete a comment from a file.
145
146
Args:
147
file_ (str): File ID
148
id_ (str): Comment ID to delete
149
150
Returns:
151
Response: Deletion confirmation
152
"""
153
```
154
155
## Types
156
157
```python { .api }
158
class Files(BaseAPI):
159
"""File operations and management."""
160
def list(self, user=None, ts_from=None, ts_to=None, types=None, count=None, page=None, channel=None): ...
161
def info(self, file_, count=None, page=None): ...
162
def upload(self, file_=None, content=None, filetype=None, filename=None, title=None, initial_comment=None, channels=None, thread_ts=None): ...
163
def delete(self, file_): ...
164
def revoke_public_url(self, file_): ...
165
def shared_public_url(self, file_): ...
166
167
@property
168
def comments(self): ... # Returns FilesComments instance
169
170
class FilesComments(BaseAPI):
171
"""File comment management."""
172
def add(self, file_, comment): ...
173
def delete(self, file_, id_): ...
174
def edit(self, file_, id_, comment): ...
175
```