如何使用Zoomnet downloadfileasync

发布于 2025-02-01 13:21:05 字数 2946 浏览 3 评论 0原文

我正在使用Nuget软件包Jericho /Zoomnet,试图下载Zoom录制(MP4)[Winform App]

我不确定downloadfileasync()< /code>有效地将文件从流中保存,我不断获得任务取消例外,

您可以指出任何类似的示例吗?

更新 所以我与包装的作者进行了交谈, 他制作了一个Beta版本以更有效地下载大文件,还向我展示了您可以添加自己的客户端对象以根据文件大小来控制超时,也需要使用configureawait(false)。

   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

这是我尝试的代码

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)
'''

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)
'''

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2025-02-08 13:21:05

我使用工作解决方案更新了上面的代码。

I updated the code above with a working solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文