I have a slack workflow which takes files input and then calls our slack bot.
I get the url_private_download link in the backend And I tried the following to download the image
`file_path = os.path.join(folder_path, file_name)
headers = {
'Authorization': f'Bearer {Slack_bot_token}'
}
# Send a GET request to download the file
response = requests.get(url_private_download, headers)
if response.status_code == 200:
# Write the content of the file to the specified location
with open(file_path, 'wb') as file:
file.write(response.content)
log.info(f"File downloaded and saved to {file_path}")
def encode_file_to_base64(file_path):
with open(file_path, "rb") as file:
file_content = file.read()
encoded_content = base64.b64encode(file_content) # Encodes to Base64
encoded_string = encoded_content.decode("utf-8") # Decode to string format
return encoded_string
encoded_file = encode_file_to_base64(file_path)
# log.info("Base64 Encoded Content:")
# log.info(encoded_file)
file_encode[file_name] = encoded_file
else:
log.info(f"Failed to download file. Status code: {response.status_code}")`
The file downloaded is corrupted and the base64 encoding is also wrong.
Please let me know how to achieve this
I have a slack workflow which takes files input and then calls our slack bot.
I get the url_private_download link in the backend And I tried the following to download the image
`file_path = os.path.join(folder_path, file_name)
The file downloaded is corrupted and the base64 encoding is also wrong.
Please let me know how to achieve this