Search code examples
apivideotwiliorecordingmkv

Twilio Video API Returns MKV File as a String in Response of Recording


I have a problem retrieving the Recordings in Twilio Video API.

I'm using C# in the back-end and have successfully gotten the Recording sids of the rooms.

 const string apiKeySid = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
                const string apiKeySecret = "byt32MXXXXXXXXXXXXXXXXXXXXX";

                TwilioClient.Init(apiKeySid, apiKeySecret);

                string recordingSid = sample.RecordingSid;
                var uri = $"https://video.twilio.com/v1/Recordings/{recordingSid}/Media";
                var response = TwilioClient.GetRestClient().Request(new Request(HttpMethod.Get, uri));

                var mediaLocation =JsonConvert.DeserializeObject<Dictionary<string, string>>(response.Content)["location"];
                using (var webClient = new System.Net.WebClient())
                {
                    string mediaContent = webClient.DownloadString(uri);
                }

This is my code to download the recording from the Twilio Servers.

The Response

Content: "\u001aEߣ\u0001\0\0\0\0\0\0\u0014B��matroska\0B��\u0002B��...." A very long text which I think is an mkv file
StatusCode: OK

The ERROR

var mediaLocation =JsonConvert.DeserializeObject<Dictionary<string, string>>(response.Content)["location"];

As the content contains gibberish, the code doesn't work from this line onwards.

What I've tried 1) Tried to copy the content, paste it in Notepad and then save the file, in Unicode as well as in ASCII code, change the format of file to ".mkv" and try to run it. P.S. Doesn't Work. 2) Tried to Download the File (both from my C# code and manually in browser) from "https://video.twilio.com/v1/Recordings/{recordingSid}/Media", gives Authentication Required Error 3) Tried my best to convert the string to mkv but to no avail.

What the Official Documentation Says

{
"location": "https://com.twilio.dev-us1.video.recording.s3.amazonaws.com/RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

} Which is not what the API returns, maybe they have changed it recently but they should update it in their documentation.

What I need help in If you have used Twilio's Video API before, can you tell me how can I retrieve the recording from the Twilio Server assuming I have the Room SID and Recording Sid of the recording.

Thanks in Advance :)


Solution

  • I solved it myself When I write this url in the browser https://video.twilio.com/v1/Recordings/{recordingSid}/Media And write the Account_Sid as the username and Account_Secret as the password, it lets me download the file directly. So what I've done is that everytime I want to access a recording, I send a GET request to this url https://video.twilio.com/v1/Recordings/{recordingSid}/Media Along with the account sid and account secret and it lets me download the recording direcly.

    I'm posting this answer for anyone who has come across this same issue in the future.