I use this code to download a file from Google Drive using the Google Drive api V3:
Function gDownload() As Boolean
Dim fileID As String = "0B-W1aRTTOB1QM3hPd0dOUFVObHM"
Dim stream = New System.IO.MemoryStream()
Dim r = service.Files.Get(fileID)
Dim m = r.MediaDownloader
m.ChunkSize = 256 * 1024
AddHandler m.ProgressChanged, AddressOf Download_ProgressChanged
mStart:
r.Download(stream)
Return True ' or False if download failed
End Function
Private Sub Download_ProgressChanged(s As IDownloadProgress)
Console.WriteLine(s.Status.ToString & " " & s.BytesDownloaded)
End Sub
This works great with a stable connection, but if I lose the connection, it stops and waits forever, even if I reconnect.
I don't have this problem with the update (upload) function in this code:
Function gUpload() As Boolean
Dim fileID As String = "0B-W1aRTTOB1QM3hPd0dOUFVObHM"
Dim stream As New System.IO.FileStream("D:\gtest\Test.mp4", System.IO.FileMode.Open)
Dim fBody As File = New File With {.Name = "Test.mp4"}
Dim r = service.Files.Update(fBody, fileID, stream, "application/octet-stream")
r.ChunkSize = ResumableUpload.MinimumChunkSize
AddHandler r.ProgressChanged, AddressOf Upload_ProgressChanged
mStart:
r.Resume()
If r.GetProgress.Status = 3 Then ' UploadStatus.Completed
Return True
Else
If MessageBox.Show("Failed. do you want to resume?", "Failed", MessageBoxButtons.YesNo) = DialogResult.Yes Then
GoTo mStart
End If
End If
Return False
End Function
Private Sub Upload_ProgressChanged(s As IUploadProgress)
Console.WriteLine(s.Status.ToString & " " & s.BytesSent)
End Sub
This works exactly the way I want, if I lose the connection for some time (15-30 seconds), it gives a message that the download failed and allows the user to resume or exit. everything works perfectly.
So my question is: how to make the boot function work as a boot function, or at least make it, not wait forever and gives an error message.