02-18-2021 03:13 AM
Hello everyone,
I am having some trouble working with files in an incident.
I have integrated an API that need a path to upload a file.
This API checks the file extension in the path and as I have seen, file paths in XSOAR incidents are something like 80_916@80. I would need to have access to an absolute path or a way to get a path with the file name at the end of it.
Maybe exists a way to move a file to a specific path or something that could help me with this issue. I haven't found any documentation about this.
Could you help me?
Thanks in advance,
Alejandro.
02-23-2021 01:20 AM
Good morning Adam,
In my integration I had already used the function getFilePath.
I have something like:
file=demisto.getFilePath(file_id)
file=open(file['path'],'rb')
Then, I use this variable as the input for the API request because if I try to open file['name'] it can't find the file. The problem is that this variable is equals to <_io.BufferedReader name='71_356@71'> and it should be <_io.BufferedReader name='myfile.xls'> to allow the API to read the extension properly.
Thanks once again,
Alejandro.
02-23-2021 03:13 AM
Now I understand. There isn't anything to be done about the filename in the incident.
I can only suggest perhaps doing something directly with the io library to manipulate the "name" in a file handle, howeverm I don't think this is possible.
One workaround would be to (excuse the pseudo code):
def get_handle(file_data):
return_handle = open(file_data['name'], "wb")
with open(file_data['path'], "rb") as fp:
return_handle.write(fp.read())
return_handle.seek(0,0)
return return_handle
def main():
args = demisto.args()
entryID = args['entryID']
file_data = demisto.getFilePath(entryID)
new_handle = get_handle(file_data)
This would temporarily write data to a file named aptly and return the handle you need. This file, though, would only exist throughout the execution of the intergation command.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!