Source
import base64 import zlib import demistomock as demisto from CommonServerPython import * from CommonServerUserPython import * def get_file_data(file_path: str, is_zip: bool = False): with open(file_path, "rb") as f: data = f.read() if is_zip: data = zlib.compress(data) return base64.b64encode(data).decode("utf-8") def main(): list_name = demisto.args()["listName"] is_zip = demisto.args()["zipFile"] == "true" entry_id = demisto.args()["entryId"] res = demisto.getFilePath(entry_id) if not res: return_error(f"Entry {entry_id} not found") file_path = res["path"] file_base64 = get_file_data(file_path, is_zip) res = demisto.executeCommand("createList", {"listName": list_name, "listData": file_base64}) if isError(res): return res return { "Contents": file_base64, "ContentsFormat": formats["text"], "HumanReadable": tableToMarkdown( "File successfully stored in list", {"File Entry ID": entry_id, "List Name": list_name, "Size": len(file_base64)} ), "HumanReadableFormat": formats["markdown"], } if __name__ in ("__main__", "__builtin__", "builtins"): demisto.results(main())
README
Encode a file as base64 and store it in a XSOAR list.
Script Data
| Name | Description |
|---|---|
| Script Type | python2 |
| Tags | Utility, list |
| Cortex XSOAR Version | 5.0.0 |
Used In
This script is used in the following playbooks and scripts.
- Get Mails By Folder Pathes
- Get Mails By Folder Paths
Inputs
| Argument Name | Description |
|---|---|
| entryId | The file entry ID. |
| listName | The list name in which to store the file. The list must exist in Demisto. |
| zipFile | Whether to zip the file before storing it in the list. |
Outputs
There are no outputs for this script.