因此,以下工作流程:
由于我是新手,所以遇到了一些问题。这是我的代码现在的样子:
import logging
import requests
import azure.functions as func
import json
SUPPORTED_CONTENT_TYPES = ['application/pdf', 'image/jpeg', 'image/png']
# Define Form Recognizer Dependencies
apim_key = "key"
model_id = "formrecognizer model id"
formrecendpoint ="endpoint"
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Function processed a Request')
# recieve the file
file = req.files.get('file')
body = None
# Analyze Forms Endpoint
endpoint = '......cognitive.microsoft.com/formrecognizer/v2.0-preview/cutom/models/modelID/analyze'
# Analyze Form
response = requests.post(endpoint, data = file, headers = {"Content-Type": '<file type>',"Ocp-Apim-Subscription-Key": apim_key})
body = response.content
#Return Response
return func.HttpResponse(body,headers={'Content-Type':'application/json'})
但这根本不起作用。
尝试通过邮递员投递文件时出现以下错误(form-data,binary)
{
"error": {
"code": "1002",
"message": "Analyze request is either invalid or missing required parameters. Refer to the API reference and retry your request."
}
}
但是在函数本身中,我得到STATUS: 200
。