C# 应用程序
我需要使用文件 ID 更新在 Gdrive 中共享的文件。
代码:
public static Google.Apis.Drive.v2.Data.File UpdateFile(DriveService service,
String fileId, String newTitle, String newDescription, String newMimeType,
String newFilename, bool newRevision)
{
try
{
// First, retrieve the file from the Google Drive.
Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Fetch();
// Set the file's new metadata.
file.Title = newTitle;
// file.Description = newDescription;
file.MimeType = newMimeType;
// Get the file's new content and read it into a memory stream
byte[] byteArray = System.IO.File.ReadAllBytes(newFilename);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
// Call the Update API method passing in the updated information.
FilesResource.UpdateMediaUpload request = service.Files.Update(file, fileId, stream, newMimeType);
// Tell Google Drive if this is a new revision of the file or not.
request.NewRevision = newRevision;
// Execute the update
request.Upload();
// Get the response back from Google Drive and set the updatedFile
//object to the returned File informational object
Google.Apis.Drive.v2.Data.File updatedFile = request.ResponseBody;
// Return the updated file object so the caller has a handle on it.
return updatedFile;
}
抛出错误:找不到文件。