使用多部分/混合的放心音频文件上传 [英] Rest-Assured Audio File Upload with multipart/mixed

查看:32
本文介绍了使用多部分/混合的放心音频文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to test the following upload content in rest-azure. It's a multipart/mixed and the first part is the body and the second part is the actual audio file:

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==--

我创建了以下测试,但不幸的是,它不起作用:

I created the below test but unfortunately, it's not working:

  @Test
  public void uploadAudio(){

    Map<String, String> jsonRequest = new HashMap<>();
    jsonRequest.put("Content-Disposition", "form-data");

    Map<String, String> jsonAttachment = new HashMap<>();
    jsonAttachment.put("Content-Disposition", "form-data");
    jsonAttachment.put("Content-ID", "duicw78fhage7f");

    given()
       .contentType("multipart/mixed; boundary=====outer123==")
       .multiPart("text", dataProvider.getAudioAttachment())
       .multiPart(new MultiPartSpecBuilder(jsonRequest).with().controlName("request")
               .and().mimeType(ContentType.JSON.withCharset("UTF_8")).build())
       .multiPart(new MultiPartSpecBuilder(jsonAttachment).with().controlName("attachment")
               .and().emptyFileName().and().mimeType("audio/wav").build())
       .queryParam("msisdn", "14565894558")
       .header("Authorization", "Basic xxxxxxxx")
       .header("Cache-Control", "no-cache")
       .body(dataProvider.getWSGUploadAudioRequest()).
    expect()
       .statusCode(200).
    when()
       .put("https://<host>/<service>/v1/audio/{msisdn}");


}

我已经多次测试过这个案例,虽然我不知道究竟是什么导致了这个问题,但问题似乎出在多部分主体组合上.我可以帮忙吗?我正在使用最新版本的放心

I've tested this case many times and it seems like the issue is with the multipart body combination although I don't know exactly which causes this issue. Can I please assist? I'm using the latest version of rest-assured

推荐答案

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

Here's how I was able to resolve this test issue:

@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 中运行良好.我希望这对其他人有帮助

I tested it and it works fine in Spring Boot. I hope this helps someone else

这篇关于使用多部分/混合的放心音频文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆