Skip to content

Commit

Permalink
Fix uploads not including filename
Browse files Browse the repository at this point in the history
  • Loading branch information
unode committed Aug 26, 2022
1 parent fcaf3ee commit c3c5450
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions mmpy_bot/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,22 @@ def upload_files(
) -> List[str]:
"""Given a list of file paths and the channel id, uploads the corresponding
files and returns a list their internal file IDs."""
file_dict = {}
file_list = []
for path in file_paths:
path = Path(path)
file_dict[path.name] = Path(path).read_bytes()
# Note: 'files' should be a name of an expected attribute in the body
# but seems to be ignored when simply uploading files to mattermost
file_list.append(
(
"files",
(
path.name,
Path(path).read_bytes(),
),
)
)

result = self.files.upload_file(channel_id, file_dict)
result = self.files.upload_file(
files=file_list, data={"channel_id": channel_id}
)
return list(info["id"] for info in result["file_infos"])

0 comments on commit c3c5450

Please sign in to comment.