@KEVIN S Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
Document Models - Analyze Document REST API
clearly talks about the allowed request body headers:
More Info here.
If you don't want to pass the urlSource
then you can explore base64Source
attribute in the request body.
This can be used to pass the base64 content of the pdf file in c:\ drive. You can follow the below approach:
import base64
import requests
import json
# Read the PDF file in binary mode, encode it to base64, and decode to string
with open("C:\\path\\to\\your\\file.pdf", "rb") as file:
base64_encoded_pdf = base64.b64encode(file.read()).decode()
# Prepare the API request body
data = {
"base64Source": base64_encoded_pdf
}
# Prepare the API request headers
headers = {
"Content-Type": "application/json",
"Ocp-Apim-Subscription-Key": "<your_subscription_key>"
}
# Send the API request
response = requests.post(
"{endpoint}/formrecognizer/documentModels/{modelId}:analyze?pages={pages}&locale={locale}&stringIndexType={stringIndexType}&api-version=2023-07-31&features={features}",
headers=headers,
data=json.dumps(data),
)
# Print the API response
print(response.json())
Please note, I haven't tested the above sample at my end. Please test it at your end and check if that works fine.
Please remember, the size of the base64 encoded string can be quite large for big PDF files, and there might be a limit on the size of the request body that the API can handle.
Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.