您无法将内容上传到application / vnd.google-apps.folder类型的文件

时间:2014-09-24 15:44:05

标签: c# google-drive-api

我想在谷歌硬盘中添加新文件夹 我使用这段代码:

   Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
   body.Title = "title";
   body.Description = "description";
   body.MimeType = "application/vnd.google-apps.folder";

   byte[] byteArray = Encoding.ASCII.GetBytes(content);
   System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
   Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request =         
                                   service.Files.Insert(body, stream, mimeType);
   Google.Apis.Drive.v2.Data.File parentFolder = request.Upload();

符合代码: request.Upload()我收到以下错误消息:您无法将内容上传到application / vnd.google-apps.folder

类型的文件

1 个答案:

答案 0 :(得分:0)

问题在于这一行

Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request =         
                               service.Files.Insert(body, stream, mimeType);

你应该做一个简单的插入。通过调用InsertMediaUpload,您告诉驱动器您正在尝试将某些内容上传到Folder实体,这当然没有意义。