使用以下代码在 Google Drive 帐户中插入文件时出现错误
'File' 是 'Google.Apis.Drive.v2.Data.File' 和 'System.IO.File' 之间的模糊引用
private static File insertFile(DriveService service, String title, String description, String parentId, String mimeType, String filename)
{
// File's metadata.
File body = new File();
body.Title = title;
body.Description = description;
body.MimeType = mimeType;
// Set the parent folder.
if (!String.IsNullOrEmpty(parentId))
{
body.Parents = new List<ParentReference>() { new ParentReference() { Id = parentId } };
}
// File's content.
byte[] byteArray = System.IO.File.ReadAllBytes(filename);
MemoryStream stream = new MemoryStream(byteArray);
try
{
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType);
request.Upload();
File file = request.ResponseBody;
// Uncomment the following line to print the File ID.
// Console.WriteLine("File ID: " + file.Id);
return file;
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
return null;
}
}