我在 C# .Net 中工作,我希望能够将图像上传到 Google Drive 中创建的文件夹。请看下面的代码。使用此代码,我可以分别制作文件夹并上传图像,但我想编写代码以在创建的文件夹中上传图像
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = "My first folder";
body.Description = "document description";
body.MimeType = "application/vnd.google-apps.folder";
// service is an authorized Drive API service instance
Google.Apis.Drive.v2.Data.File file = service.Files.Insert(body).Fetch();
Google.Apis.Drive.v2.Data.File body1 = new Google.Apis.Drive.v2.Data.File();
body1.Title = "My first folder";
body1.MimeType = "image/jpeg";
//------------------------------------------
byte[] byteArray = System.IO.File.ReadAllBytes("Bluehills.jpg");
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "image/jpeg");
request.Upload();
Google.Apis.Drive.v2.Data.File file1 = request.ResponseBody;
Console.WriteLine("File id: " + file1.Id);
Console.WriteLine("Press Enter to end this process.");
Console.ReadLine();