Mocking audio download

170 views
Skip to first unread message

Fahima Karim

unread,
Sep 8, 2021, 6:41:24 AM9/8/21
to wiremock-user
Hi,

I am using Wire Mock standalone jar. I want to mock the audio download that the api brings back in response using Wire Mock. 

I have an JSON mapping under "mappings" dir
{"request":
    {
      "urlPath": "/v2/archive_files",
      "method": "GET",
      "queryParameters" : {   
  "from" : {
            "matches" : "^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})Z$"
          },
  "to" : {
            "matches" : "^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})Z$"
          },
  "page_size" : {
            "matches" : "15"
          },
          "query_date_type" : {
            "matches" : "archive_complete_time"
          }
      }
    }, "response": {"bodyFileName": "archive_files.xml"}}

The contents of file archive_files.xml is in "__files" dir:
{"from":"2021-08-25T09:05:13Z","to":"2021-09-01T09:05:15Z","page_size":15,"next_page_token":"yE7m5a2Xrjl6sTwaXdovVxlBp3PgbC6cpI2","meetings":[{"uuid":"qqMZTqziRYCNnoaPHkGSyQ==","id":83122820832,"host_id":"SgKR-aakRfus5YjbX0nnVg","topic":"Client42's Zoom Meeting","type":1,"start_time":"{{date (parseDate request.query.from) offset='+4 hours'}}","timezone":"","duration":0,"total_size":1617957,"recording_count":2,"archive_files":[{"id":"469fb5d7-a0b2-47a1-88e0-9ed585e03ddd","file_type":"M4A","file_extension":"M4A","file_size":744318,"download_url":"https://us06web.zoom.us/rec/archive/download/04hCulsA-uQFCP1SE0aNv14DgmpSx-H4FSsdBH1Gnf3C92wXt-QrSZrh17_eH-8JmKovxGXFSGqu9bm2.F_a92oCWxuw5TJ5m","status":"completed","recording_type":"audio_only"},{"id":"c9b93ae5-cc0d-4ee3-8821-339ed701ee72","file_type":"MP4","file_extension":"MP4","file_size":873639,"download_url":"https://us06web.zoom.us/rec/archive/download/mBnPFeH9NBIc1omVjVouGsHFzRisAfndye3iqH0t8LoMrlMOMCeNRpwI49p9rGeGWlim1beSzhbRjBU_.Z8LF50I_CvtnbdOp","status":"completed","recording_type":"shared_screen_with_speaker_view"}]}]}

I want to mock the "download_url" value using Wire Mock but I am not sure what approach can be taken. Please can I get some suggestion as to what Wire Mock can offer to aid in this. Thanks!

Kind regards,
Fahima

thilmano_wiremockuser

unread,
Sep 8, 2021, 8:04:35 AM9/8/21
to wiremock-user
Hi..

try replacing the download url with the same wiremock url. lets assume your wiremock runs locally on 8080. you can replace the 

"download_url":"http://localhost:8080/<url path>"

Note: make sure you have the matching stubs accordingly.

Fahima Karim

unread,
Sep 9, 2021, 7:32:17 AM9/9/21
to wiremock-user
Hi, Thanks for this suggestion. I think this is the correct way forward as I am getting a download now, however not in the .M4A format. It just downloads with no file format at all. I've placed the audio_only.m4a file under "__files" directory.

JSON:
{"request": {"method": "GET","url": "/rec/archive/download/04hCulsA-uQFCP1SE0aNv14DgmpSx-H4FSsdBH1Gnf3C92wXt-QrSZrh17_eH-8JmKovxGXFSGqu9bm2.F_a92oCWxuw5TJ5m"},"response": {"bodyFileName": "audio_only.m4a"}}

XML Mapping:
{"from":"2021-08-25T09:05:13Z","to":"2021-09-01T09:05:15Z","page_size":15,"next_page_token":"yE7m5a2Xrjl6sTwaXdovVxlBp3PgbC6cpI2","meetings":[{"uuid":"qqMZTqziRYCNnoaPHkGSyQ==","id":83122820832,"host_id":"SgKR-aakRfus5YjbX0nnVg","topic":"Client42's Zoom Meeting","type":1,"start_time":"{{date (parseDate request.query.from) offset='+4 hours'}}","timezone":"","duration":0,"total_size":1617957,"recording_count":2,"archive_files":[{"id":"469fb5d7-a0b2-47a1-88e0-9ed585e03ddd","file_type":"M4A","file_extension":"M4A","file_size":744318,"download_url":"https://localhost:8080/rec/archive/download/04hCulsA-uQFCP1SE0aNv14DgmpSx-H4FSsdBH1Gnf3C92wXt-QrSZrh17_eH-8JmKovxGXFSGqu9bm2.F_a92oCWxuw5TJ5m","status":"completed","recording_type":"audio_only"},{"id":"c9b93ae5-cc0d-4ee3-8821-339ed701ee72","file_type":"MP4","file_extension":"MP4","file_size":873639,"download_url":"https://us06web.zoom.us/rec/archive/download/mBnPFeH9NBIc1omVjVouGsHFzRisAfndye3iqH0t8LoMrlMOMCeNRpwI49p9rGeGWlim1beSzhbRjBU_.Z8LF50I_CvtnbdOp","status":"completed","recording_type":"shared_screen_with_speaker_view"}]}]}

The bodyFileName value I tried changing the ext. to xml and mp4 and the name of the file itself but no luck Any suggestion as to how to have it download in M4A format?

Kind regards,
Fahima

Tom Akehurst

unread,
Sep 9, 2021, 7:35:10 AM9/9/21
to wiremock-user
You probably just need to add a Content-Type response header to the download stub with the appropriate MIME type for m4a.

Fahima Karim

unread,
Sep 9, 2021, 9:55:24 AM9/9/21
to wiremock-user
Hi,

I've done as suggested:

{"request": {"method": "GET","url": "/rec/archive/download/audio_only.m4a"},"response": { "headers": { "Content-Type": "audio/m4a"}, "bodyFileName": "audio_only.m4a"}}

But this has not changed the download to any format. Anything else you can recommend?

Regards,
Fahima

thilmano_wiremockuser

unread,
Sep 9, 2021, 10:06:58 AM9/9/21
to wiremock-user
please try  { "Content-Type": "audio/mp4"}

check below for more details

Fahima Karim

unread,
Sep 9, 2021, 10:20:42 AM9/9/21
to wiremock-user
Hey, 

Thanks. This has helped me get to the point where the browser plays the audio_only.m4a file, but downloading has now entirely stopped which is a requirment.
Please see details below and open to any suggestions to aid in this. Many Thanks!

JSON:
{"request": {"method": "GET","url": "/rec/archive/download/audio_only"},"response": { "headers": { "Content-Type": "audio/mp4"}, "bodyFileName": "audio_only.m4a"}}

URL redirects to:
2021-09-09_15h17_03.png

Wire Mock console:
2021-09-09_15h17_03.png

thilmano_wiremockuser

unread,
Sep 9, 2021, 10:35:24 AM9/9/21
to wiremock-user
fantastic.. could you please play around with these response headers in your stubs.. this would enable downloading

"Content-Disposition": "inline"
"Content-Disposition": "attachment"
"Content-Disposition": "attachment"; filename="filename.jpg"

Fahima Karim

unread,
Sep 10, 2021, 11:13:13 AM9/10/21
to wiremock-user
it worked :D Thanks a bunch!
Reply all
Reply to author
Forward
0 new messages