Upload documents into Layar
Uploading a document
To upload a document, we'll be using the Source Document API to add a document to the Layar data fabric.
The first step is to upload the document to the Layar API
curl 'https://YOUR_SERVER_HERE/layar/sourceDocument' \
-X POST \
-H 'Authorization: Bearer YOUR_TOKEN_HERE' \
-F 'name=filename.pdf' \
-F 'file=@path/to/local/file/filename.pdf'
uploadDocsUri = f'{envUrl}/layar/sourceDocument'
header = {
'Authorization': f"Bearer {token}",
'X-Vyasa-Client': 'layar',
'X-Vyasa-Data-Providers' : 'sandbox.certara.ai'
}
body = {'name': 'Test_doc.docx'}
files=[
('file',('Test_doc.docx',open('C:/Users/dschindl/Documents/Test_doc.docx','rb')))
]
response = requests.post(uploadDocsUri,
headers = header,
data = body,
files = files,
)
documentId = response.json().get('id')
print(documentId) #optional
The response of the document upload will contain an ID that you can use to reference the document in the future. In the example below, the ID is AYXGsE6FbZ95yV31x8iZ
{
"cortexDocumentType": "DOCUMENT",
"createdByUser": 25001,
"id": "AYXGsE6FbZ95yV31x8iZ",
"metadata": {},
"mimeType": "application/pdf",
"name": "filename.pdf"
}
Processing of documents after upload is an asynchronous process. You can monitor the status of the uploaded document by calling the Source Document Status API using the ID returned above (e.g. in this instance it's AYXGsE6FbZ95yV31x8iZ
)
curl -X GET 'https://YOUR_SERVER_HERE/layar/sourceDocument/AYXGsE6FbZ95yV31x8iZ/status'
-H 'Accept: application/json'
-H 'Authorization: Bearer YOUR_TOKEN_HERE'
docStatusUri = f'{encUrl}/layar/sourceDocument/{documentId}/status'
response = requests.get(docStatusUri,
headers = header
)
print(response.text)
As the document is processed, the API will return with a status of Processing
{
"percent":75,
"message":"Processing..."
}
Once the document is uploaded and ready for querying and use in the data fabric, the status will change to 100% and the message will read Complete
{
"percent":100,
"message":"Complete!"
}
Updated 6 months ago
Now that we have a subset of documents to work with, we can add those documents to a set.