Python: Capture The Output Of A Rest Api Based Dms Service Post Uploading Document
I am trying to upload a file to a DMS via REST API. Each time I upload the file to DMS, an unique doc_id is generated which needs to be saved in DB. I am trying out the following c
Solution 1:
Ok, I found the trick!!
I should use
data = resp.json()
doc_id = data['doc_id''
return doc_id
So the complete code would be:
def upload_sotr(filepath:str,file_name:str):
upload_url = 'dms_url_path'
f = open(os.path.join(filepath,file_name),'rb')
files = {"file":(os.path.join(filepath,file_name),f)}
resp = requests.post(url=url,files=files)
if resp.status_code==201:
data = resp.json()
doc_id = data['doc_id']
return doc_id
else:
strg='Failure'return strg
Post a Comment for "Python: Capture The Output Of A Rest Api Based Dms Service Post Uploading Document"