首页 > 解决方案 > 使用 vb.net 将大文件上传到谷歌驱动器

问题描述

我的代码仅适用于小于 5 mb 的文件,但是当我尝试使用更多 5 mb 的文件时出现异常。

Private Sub UploadFile()
        If service.ApplicationName <> "Google Drive" Then CreateService()
        Dim thefile As New File With {
            .Name = fileName,
            .Description = "A Backup File",
            .MimeType = "application/octet-stream"
        }
        Dim uploadrequest As FilesResource.CreateMediaUpload
        Dim bytearry As Byte() = System.IO.File.ReadAllBytes(filePath)
        Try
            Using stream = New System.IO.MemoryStream(bytearry, System.IO.FileMode.Open)
                uploadrequest = service.Files.Create(thefile, stream, "application/octet-stream")
                uploadrequest.Fields = "id"

                'MsgBox(uploadrequest.GetProgress.Status.ToString())
                uploadrequest.Upload()
            End Using
            Dim file As File = uploadrequest.ResponseBody
            My.Settings.lastFileUploaded = fileName
        Catch ex As Exception
            MsgBox("error Upload Failed:" + ex.StackTrace)
        End Try
        MsgBox("upload Finished`enter code here` " + file.Id)enter code here
    End Sub

异常图像

标签: vb.netgoogle-drive-api

解决方案


推荐阅读