vb.net无法上传我的文件在谷歌驱动器
问题描述:
我使用谷歌驱动器api上传PDF文件(与vb.net),我搜索了很多教程在这个和另一个网站(如何获得谷歌驱动器API在vb.net中,如何上传...),最后我已经成功做到了 但问题,没有文件在传动vb.net无法上传我的文件在谷歌驱动器
这里加入是我的代码
Private Sub btn_save_Click(sender As Object, e As EventArgs) Handles btn_save.Click
Dim filename As String = fichier.FileName 'from selected file in openfiledialog
CreateService()
UploadFile(filename)
End Sub
Private Service As DriveService = New DriveService
Private Sub CreateService()
Dim ClientId = "*********"
Dim ClientSecret = "****************"
Dim MyUserCredential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {.ClientId = ClientId, .ClientSecret = ClientSecret}, {DriveService.Scope.Drive}, "user", CancellationToken.None).Result
Service = New DriveService(New BaseClientService.Initializer() With {.HttpClientInitializer = MyUserCredential, .ApplicationName = "Google Drive VB Dot Net"})
End Sub
Private Sub UploadFile(FilePath As String)
Me.Cursor = Cursors.WaitCursor
CreateService()
Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath)
Dim Stream As New System.IO.MemoryStream(ByteArray)
Me.Cursor = Cursors.Default
MsgBox("Upload Finished")
End Sub
当我执行我的应用程序,结果是
但我找不到驱动器中的任何文件
答
您正在调用CreateService()两次,但从未使用它来上传任何内容。
Private Sub UploadFile(FilePath As String)
Me.Cursor = Cursors.WaitCursor
CreateService()
Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath)
Dim Stream As New System.IO.MemoryStream(ByteArray)
'' ---------------------------------------------------------
'' Here you'll going to use the service to upload your data
'' with Service.Files.Create()
'' ---------------------------------------------------------
Me.Cursor = Cursors.Default
MsgBox("Upload Finished")
End Sub
插入不固定fileresource –
的一员,与V3将使用Files.Create() –
我很坚持,我如何使用它V2 API(举个例子) –