Facing issue while trying to download file using Rest API
Hi All,
i was trying to list and download file from a folder.
For listing,
http://CSurl/otcs/cs.exe/api/v2/nodes/<id>/nodes where am parsing the json and taking the data id. Then i am giving as input the above received document id to below api
http://CSurl/otcs/cs.exe/api/v2/nodes/<id>/content
When am trying to execute the API from postman, its is displaying content like showing the content inside that word document, instead of downloading.
Can some one please help me with an input here so that i can download the doc through an API?
Thanks in advance.
Answers
-
Hello @HSS2021 ,
Now the response is getting downloaded with an error required input argument func not specified.
Am not getting the correct file downloaded here.
0 -
Hi,
Send and download worked here. while writing the code in python, how i can do the same and download content?
Writing response into a file will work?
0 -
Hello,
And yes, writing the response to a file will work in Python. You can use the requests library to do that and iterate through the request to write it into a file chunk by chunk
with requests.get(URL,headers=headers,stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)0 -
Hi @HSS2021 ,
Thanks for your time to looking in to this, unfortunately using above snippet in python, am able to generate file, but its coming with no content.
When further checked its not entering the above for loop.
Do you have any clue why it is?
0 -
I am not sure what is wrong with your code. however this works for me. Its a rudimentary script (obviously with its faults and issues so take it as is) but it works for quick scripting
import requests
URL = "http://SERVERNAME/OTCS/cs.exe/api/v2/nodes/187261/content?action=download"
ticket = "TicketFromApi/V1/Auth"
headers ={'otcsticket':ticket}
local_filename = "C:\\edit.docx"
with requests.get(URL,headers=headers,stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)In the above example, nodeID is 187261, and you are posting the file to C:\edit.docx
insert the otcsticket under the 'ticket' variable.0
Categories
- All Categories
- 122 Developer Announcements
- 53 Articles
- 149 General Questions
- 147 Thrust Services
- 56 OpenText Hackathon
- 35 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 917 Cloud Fax and Notifications
- 84 Digital Asset Management
- 9.4K Documentum
- 31 eDOCS
- 181 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 8 XM Fax
- Follow Categories