0

I'm using a Nuget package Jericho /ZoomNet, trying to download a zoom recording (mp4) [winform App]

I'm not sure how the DownloadFileAsync() works to save the File from the Stream, I keep getting task cancelled exception

Can you point to any similar examples ?

UPDATE So i talked to the Author of the package, he made a beta release to download large files more efficiently, and also showed me you can add your own client object to control the timeout according to file size, also using the ConfigureAwait(False) was necessary.

   Dim myHttpClient = New HttpClient() With {            
    .Timeout = TimeSpan.FromMinutes(10)                 }
    Dim azoomClient = New ZoomClient(connectionInfo, 
    myHttpClient)

    Dim sourceStream = Await 
azoomClient.CloudRecordings.DownloadFileAsync(fdownloadFileName, ct).ConfigureAwait(False)

    Using outStream = File.OpenWrite(DestFileName)
                sourceStream.CopyTo(outStream)
    End Using

This is the code I've tried

Private azoomClient = New ZoomClient(connectionInfo)
Dim fdownloadFileName As String = "c:\zoomrec1.mp4"
Dim ct As New Threading.CancellationToken
Dim sourceStream As Stream
sourceStream = Await azoomClient.CloudRecordings.DownloadFileAsync(fdownloadFileName, ct).ConfigureAwait(False)

DumpStream(sourceStream, DestFileName)
Private Async Function DumpStream(ByVal outStream As Stream, ByVal outputFileName As String) As Task
    Try

        '  Dump the contents of a stream to a file
        outStream.Flush()
        Dim SavePos As Long = outStream.Position        '  Save the original position in the stream
        outStream.Seek(0, SeekOrigin.Begin)
        Dim f As Stream = File.OpenWrite(outputFileName)
        CopyStream(outStream, f)
        outStream.Position = SavePos                     '  Go back to the original postion in the stream
        f.Close()
    Catch ex As Exception
        MessageBox.Show("Error:DumpStream()>" & ex.Message)
    End Try
End Function

Public Shared Sub CopyStream(ByVal input As Stream, ByVal output As Stream)
    Try
        '  Copy the contents of one stream to another stream
        Dim buf As Byte() = New Byte(8 * 1024 - 1) {}      '  A buffer for storing data while copying
        Dim len As Integer
        len = input.Read(buf, 0, buf.Length)
        While len > 0
            output.Write(buf, 0, len)
            len = input.Read(buf, 0, buf.Length)
        End While
    Catch ex As Exception
        MessageBox.Show("Error:CopyStream()>" & ex.Message)
    End Try
End Sub
'''
 i can get the download url filename with this call,

'''
    Dim apiKey = "abc" Dim apiSecret = "123" 
    Dim connectionInfo As New JwtConnectionInfo(apiKey, apiSecret)  
    Dim v As Object = azoomClient.CloudRecordings.GetRecordingInformationAsync(MeetingID) 
    Dim modelsRecording = Await v
   downloadFileName = CStr(modelsRecording.RecordingFiles.Where(Function(z) 
   z.FileType = Models.RecordingFileType.Video)(0).DownloadUrl)
'''
George
  • 11
  • 4
  • Is there a reason for .ConfigureAwait(False)? What happens if you omit that from your DownloadFileAsync call? – Hursey May 26 '22 at 20:48
  • I tried without, same error , i think it might be easier to use httpclient and url with token ? – George May 27 '22 at 04:04
  • Well I would say as long as you're authenticating correctly(which you've not shown) What you've got should be ok. Perhaps it might be an idea to post it in the Issues for ZoomClient https://github.com/Jericho/ZoomNet/issues – Hursey May 27 '22 at 04:12
  • Ahh... so it's likey you're not authenticating then. Maybe check the docs for ZoomNet which has a how to connect with oAuth example – Hursey May 27 '22 at 04:18
  • Rather than putting blocks of near unreadable code in comments, update your question with the relevant details where you can format it nicely for others to read – Hursey May 27 '22 at 04:50

1 Answers1

0

I updated the code above with a working solution.

George
  • 11
  • 4