Train a Form Recognizer model with labels using REST API and Python (multiple file data extraction in single request) RRS feed

  • Question

  • Actually, I have uploaded the single file for data extraction using Cognitive Services, successfully able to extract data. But now I want to browse the multiple files for data extract in a single post request.

    Is this possible to pass multiple files in single request?

    Here is my code:

    post_url = endpoint + "/formrecognizer/v2.0-preview/custom/models/%s/analyze" % model_id
        textResult = ''
        error_message = None
        if (contentType == 'pdf'):
            error, pdfFilename = decrypt_pdf(filename, password=file_password)
            filename = pdfFilename
            error_message = error
        if(not error_message):
            x = 'application' if contentType == 'pdf' else 'image'
            headers = {
                # Request headers
                'Content-Type': f'{x}/{contentType}',
                'Ocp-Apim-Subscription-Key': apim_key,
            with open(filename, "rb") as f:
                data_bytes =
                resp = post(url = post_url, data = data_bytes, headers = headers, params = params)
                if resp.status_code != 202:
                    textResult = f"POST analyze failed:\n{resp.text}"
                get_url = resp.headers["operation-location"]
                textResult = get_layout_results(get_url, resultType)
            except Exception as e:
                textResult = f"POST analyze failed:\n{str(e)}"
            textResult = error_message
        return textResult

    Tuesday, June 30, 2020 2:38 PM

All replies

  • Hi Gary,

    The analyze operation supports only one document or form in a single request. The input requirements of the document or form along with the no. of pages that are supported is documented here.

    If you have already combined multiple documents in a single one and passed it to the API please ensure it does not contain any complex tables like nested tables or merged headers or cells as this would cause the form recognizer to fail.


    Thursday, July 2, 2020 10:03 AM