前提・実現したいこと
テキストファイルをGoogle Driveにアップロードするプログラムを作成しています。
アップロードには以下のコードを用いたのですが、同名ファイルが新規ファイルとしてアップロードされてしまいます。(Drive内が同名ファイルだらけになります。)
ファイルをアップロードしたときDrive内に
同名ファイルがなければ新規アップロード
同名ファイルがあれば上書きアップロード
とするにはどうすればいいのでしょうか?
よろしくお願い致します。
発生している問題・エラーメッセージ
Google Driveへの上書きアップロードができない
該当のソースコード
VB.net
1Private Sub createservice() 2Dim clientid = "取得したもの" 3Dim clientsercret = "取得したもの" 4 5Dim uc As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {.ClientId = clientid, .ClientSecret = clientsercret}, {DriveService.Scope.Drive}, "user", CancellationToken.None).Result 6service = New DriveService(New BaseClientService.Initializer() With {.HttpClientInitializer = uc, .ApplicationName = "Google Drive VB Dot NET"}) 7End Sub 8 9 10Private Sub uploadfile(ByVal filepath As String) 11If service.ApplicationName <> "Google Drive VB Dot NET" Then createservice() 12Dim thefile As New File 13thefile.Title = "Demo" 14thefile.Description = "A demo Document" 15thefile.MimeType = "text/plain" 16 17Dim bytearray As Byte() = System.IO.File.ReadAllBytes(filepath) 18Dim stream As New System.IO.MemoryStream(bytearray) 19Dim uploadrequest As Google.Apis.Drive.v2.FilesResource.InsertMediaUpload = service.Files.Insert(thefile, stream, thefile.MimeType) 20uploadrequest.Upload() 21Dim file As File = uploadrequest.ResponseBody 22End Sub 23 24 25Sub main() 26uploadfile("テキストファイルの場所") 27End Sub
補足情報(FW/ツールのバージョンなど)
VisualBasic2017
Google Drive API.v2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/11 07:08 編集