所以。。。我正在尝试使用Visual Basic中的更新功能来更新文件内容和元数据。使用第一段代码来调用它。但是,该代码会运行,但不会更新驱动器中的文件,并给出0个错误。我不确定代码出了什么问题,因为我有另一段代码可以很好地更新元数据。任何帮助都将不胜感激!
bob.updateFile(bob.service, "0Bzqp8R7eFke2aHZqZHdYZ2RpYjg", "listbox.txt", "Test #2", ".txt", "meme.txt ", True)
Public Function updateFile(service As DriveService, fileId As String, newTitle As String, newDescription As String, newMimeType As String, newFilename As String, newRevision As Boolean) As File
Try
' First retrieve the file from the API.
Dim file As File = service.Files.Get(fileId).Execute
' File's new metadata.
file.Title = newTitle
file.Description = newDescription
file.MimeType = newMimeType
' File's new content.
Dim byteArray() As Byte = System.IO.File.ReadAllBytes(newFilename)
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream(byteArray)
'Send the request to the API.
Dim request As FilesResource.UpdateMediaUpload = service.Files.Update(file, fileId, stream, newMimeType)
request.NewRevision = newRevision
request.Upload()
Dim updatedFile As File = request.ResponseBody
Return updatedFile
stream.Close()
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
End Try
End Function
===
这是元数据的工作代码
Public Function updateMetadata(ByVal service As DriveService, ByVal fileId As String, ByVal newTitle As String, ByVal newDescription As String, ByVal newMimeType As String, ByVal newRevision As Boolean) As File
Try
' First retrieve the file from the API.
Dim file As File = service.Files.Get(fileId).Execute
file.Title = newTitle
file.Description = newDescription
file.MimeType = newMimeType
' Update the file's metadata.
Dim request As FilesResource.UpdateRequest = service.Files.Update(file, fileId)
request.NewRevision = newRevision
Dim updatedFile As File = request.Execute
Return updatedFile
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
Return Nothing
End Try
End Function
嘿,伙计们,谢谢你们的帮助!
这是工作代码,问题是mime类型不必更改!
bob.updateFile(bob.service, "0Bzqp8R7eFke2aHZqZHdYZ2RpYjg", "listbox.txt", "Test #2", ".txt", "meme.txt ", True)
Public Function updateFile(service As DriveService, fileId As String, newTitle As String, newDescription As String, newMimeType As String, newFilename As String, newRevision As Boolean) As File
Try
' First retrieve the file from the API.
Dim file As File = service.Files.Get(fileId).Execute
' File's new metadata.
file.Title = newTitle
file.Description = newDescription
'file.MimeType = newMimeType
' File's new content.
Dim byteArray() As Byte = System.IO.File.ReadAllBytes(newFilename)
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream(byteArray)
'Send the request to the API.
Dim request As FilesResource.UpdateMediaUpload = service.Files.Update(file, fileId, stream, newMimeType)
request.NewRevision = newRevision
request.Upload()
Dim updatedFile As File = request.ResponseBody
Return updatedFile
stream.Close()
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
End Try
End Function