1
votes

I want to create a post request on Azure API Management with a form-data format. I must send a file and data in body to an url but don't see how to send both.

I get http code from postman where it works: request in postman

I don't find way to send my post request with file and data. When I tried to send with one of two I get the response:

HTTP/1.1 500 Erreur Interne de Servlet

cache-control: no-cache, no-store, max-age=0, must-revalidate
connection: close
content-language: fr
content-type: text/html;charset=utf-8
date: Thu, 16 Jul 2020 12:21:46 GMT
expires: 0
ocp-apim-trace-location: https://apimstuj2itdypxpozialwwt.blob.core.windows.net/apiinspectorcontainer/UcMgQhu6NisyHHuKEITNDw2-235?sv=2018-03-28&sr=b&sig=Eno9E9bzDcwFOC%2Brl88RY3%2Fq955Ly%2F6r1uyIO0eRwQM%3D&se=2020-07-17T12%3A21%3A45Z&sp=r&traceId=3a143ab6435b46d29e69b30eed34fd23
pragma: no-cache
strict-transport-security: max-age=31536000 ; includeSubDomains
transfer-encoding: chunked
vary: Origin
x-application-context: application
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.47 - Rapport d''erreur</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>Etat HTTP 500 - Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</h1><div class="line"></div><p><b>type</b> Rapport d''exception</p><p><b>message</b> <u>Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found</u></p>

I tried to put a boundary in request header and body but I had the same error. I have the following body: Body content

1

1 Answers

0
votes

OpenAPI v3 support in Azure API Management includes fixes and improvements to the preview functionality—for example, it enables support for multipart/form-data content type.

In OpenAPI 3.0, request body (including form data) is defined using the requestBody keyword instead of in: formData parameters.

"paths": {
  "/api/rmt-create-request": {
    "post": {
      "tags": [
        "RMT APIs"
      ],
      "description": "Return newly created request data",
      "operationId": "create-new-rmt-request",
      "requestBody": {
        "content": {
          "multipart/form-data": {    // or  "application/x-www-form-urlencoded" - depending on what you need
            "schema": {
              "type": "object",
              "properties": {
                "rootNodeName": {
                  "type": "string",
                  "description": "Root node class name for item"
                }
              }
            }
          }
        }
      }
    }
  }
}

For more details, you could refer to this article.