首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ZoomNet DownloadFileAsync

如何使用ZoomNet DownloadFileAsync
EN

Stack Overflow用户
提问于 2022-05-26 13:22:41
回答 1查看 70关注 0票数 0

我正在使用Nuget软件包Jericho /ZoomNet,试图下载一个缩放录音(mp4) winform应用程序

我不确定DownloadFileAsync()是如何从流中保存文件的,我一直得到任务取消的异常

你能指出类似的例子吗?

UPDATE所以我和包的作者谈了谈,他发布了一个测试版来更有效地下载大型文件,还向我展示了您可以添加自己的客户端对象来根据文件大小来控制超时,还需要使用ConfigureAwait(False)。

代码语言:javascript
复制
   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

这是我试过的代码

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

DumpStream(sourceStream, DestFileName)
代码语言:javascript
复制
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)
'''
EN

回答 1

Stack Overflow用户

发布于 2022-06-01 13:53:00

我用一个可行的解决方案更新了上面的代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72392546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档