Layer7 API Management

  • 1.  Uploading a file to a REST policy using curl

    Posted Dec 08, 2017 10:24 AM

    I am trying to develop a policy that accepts a file sent from curl. As far as I can tell the following curl command is correct:

     

    curl -d @file.xml http://myapigateway:8080/resttest

     

    On the API Gateway, I have the following simple policy with a single assertion:

     

    "Return Template Response to Requestor" with a content type of text/json; charset=UTF-8 and a body of {"status":"ok"}

     

    Enabling the debugger shows that request.mainpart is null when I try to send a file of about 4.5 megabytes. If I send a file of 1 megabyte, request.mainpart contains the contents of the file.

     

    The headers sent by curl are:

    • "accept:*/*"
    • "content-length:4731313"
    • "content-type:application/x-www-form-urlencoded"
    • "expect:100-continue"
    • "host:myapigateway:8080"
    • "user-agent:curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"

     

    What is the correct way to allow a REST request to a policy on the API Gateway to upload a file in this way? I assume the API Gateway is able to accept larger files?

     

    I'm using curl 7.19.7 and API Gateway 8.4



  • 2.  Re: Uploading a file to a REST policy using curl
    Best Answer

    Broadcom Employee
    Posted Dec 08, 2017 11:50 AM

    Good morning,

     

    There is a couple things you can look at:

     

    1) The default limit on the size of a request message is 2 MB to ensure that a client does not attempt to overrun the gateway with large files. You can modify this limit by change the cluster wide property io.xmlPartMaxBytes

    2) Depending on the content of the file you may look to change the Content-type being used. This can be done by adding in the - H option in the curl command: -H "Content-Type: application/xml"

    3) If the content of the file is not textual in nature then the mainpart variable will not be able to display the content say for binary payloads.

     

    Sincerely,

     

    Stephen Hughes

    Director, CA Support



  • 3.  Re: Uploading a file to a REST policy using curl

    Posted Aug 24, 2018 10:26 AM

    Stephen, would you be able to answer a related question?