使用multipart / mixed上传Rest-Assured音频文件

时间:2018-05-25 18:26:48

标签: java rest-assured

我试图在rest-azure中测试以下上传内容。它是一个多部分/混合,第一部分是正文,第二部分是实际的音频文件:

assert(test == "Hello")

我创建了以下测试,但遗憾的是,它无效:

PUT /baseUri/service/v1/audio/14255894558 HTTP/1.1
Host: p18web.stg.example.com
Authorization: Basic XXXXXXXXXXXXXXXX
Content-Type: multipart/mixed; boundary="====outer123=="
Cache-Control: no-cache


--====outer123==
Content-Disposition: form-data; name="request";
Content-Type: application/json; charset=UTF-8

{
  "object": {
  "parentFolderPath": "Media/VR",
   "attributes": {
     "attribute": [
      {
      "name": "Date",
      "value": "2014-03-17T12:37:59Z"
    },
    {
      "name": "Message-Id",
      "value": "950124.162336@example.com"
        }
      ]
    }
  }
}
 --====outer123==
 Content-Disposition: form-data; name="attachment"; filename="";Content-ID: 
 duicw78fhage7f
 Content-Type: audio/wav

 UklGRjItFABXQVZFZm10IBAAAAABAAIARKwAABCxAgAEABAAZGF0YZgsFACn/5X/ff+D/xb/Hf8q/wP/fwAQANACQwJHBdMEGwfZBlEIOghmCVMJoAqdCt0L5QvkDP4MLw4yDjoQGBB/EygTZRjEF08fWh40KAUnvjHWMDI5IjljPIo9tDuXPZw5mTv1OH06hzqoO7088z3aPWY/Nz0ZP8A7oD3hOnk83DvuPOQ+iz81Q7tDHEfjRwhJWEr7SKhKcEgSSgxJSUowSzNMdE2RTvZNnU+ITHlOt0p3TJxK0ksETbxNxFBkUYlTiFRsVMdV/FQzVtNXWlh2/nfUduZ3u3bQd6t2tXefdq93gHaJd292d3djdmZ3QHZOdyx2L3cadiF3AXYGd+t17nbrdeJ2w3XOdrB1o3aqdaB2kXWWdnh1dnZvdWZ2YHVUdjp1OHYvdSt2IXUadgh1/XX1dOt15nTfddV0xnW5dKh

--====outer123==--

我已多次测试此案例,似乎问题出在多部分身体组合上,尽管我不确切知道导致此问题的原因。我能帮忙吗?我使用的是最新版的休息保障

1 个答案:

答案 0 :(得分:0)

以下是我能够解决此测试问题的方法:

@Test(dependsOnGroups = {"init"})
public void uploadAudio() throws IOException{
    url = (baseURI + "/" + basePath + dataProvider.uploadAudioPath()).replaceAll("\\s","");
    logger.debug("Testing " + url);

    File file = new ClassPathResource("uploadAudio.txt").getFile();

    given()
       .contentType("multipart/mixed; boundary=\"====outer123==\"")
       .body(file)
       .pathParam("param", "14255894558")
       .header("Authorization", dataProvider.getToken()). 
    expect()
       .statusCode(200).
    when()
       .put(url);

我测试了它,它在Spring Boot中运行良好。我希望这有助于其他人