Service Virtualization

 View Only
Expand all | Collapse all

How to read the content of a file attachment using filters or SDPH?

  • 1.  How to read the content of a file attachment using filters or SDPH?

    Posted May 27, 2025 03:23 PM

    Hello,

    When a POST call is made with the "form-data" and a file is attached with a file name, how to read the content of the file attachment?

    Ex: In a POST call, when a file is attached with file name 'request_body' and the content of the file is a JSON payload, we need to read just the JSON payload within the file.

    We tired the below code to achieve it, but we get some extra details along with the file content content

    String incomingfile = lisa_vse_request.getBodyText();
    testExec.setStateValue("fileContent", incomingfile);

    The Output is as below:

    ----------------------------972913604387560689945330
    Content-Disposition: form-data; name="requestFile"; filename="request_body"
    Content-Type: application/json

    {
        "name": "Alice Brown",
        "sku": "54321",
        "price": 199.95,
        "shipTo": {
            "name": "Bob Brown",
            "address": "456 Oak Lane",
            "city": "Pretendville",
            "state": "HI",
            "zip": "98999"
        },
        "billTo": {
            "name": "Alice Brown",
            "address": "456 Oak Lane",
            "city": "Pretendville",
            "state": "HI",
            "zip": "98999"
        }
    }

    ----------------------------972913604387560689945330--

    Expected Result:

    Only the content of the file attached in the API request. 

    How to achieve this feature? Do we have any option other than the SDPH?

    Thank you



  • 2.  RE: How to read the content of a file attachment using filters or SDPH?

    Broadcom Employee
    Posted May 28, 2025 01:45 PM

    Hi Shanmuga, 

    The knowledge article Create Virtual Service for Multipart Form Data  should help you with what you are looking. 

    Prema