I am working on a project which I wish to upload a file(s) to my Google drive an get back it's ID using .net Maui cross platform. I don't know where and how to start. Please can someone help.
Loading
I am working on a project which I wish to upload a file(s) to my Google drive an get back it's ID using .net Maui cross platform. I don't know where and how to start. Please can someone help.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Pasang TamangRank #449 · 5.6K reputationPosted Jan 1, 2023, 12:51 AM EST
Hi,
You can use Google Deive API. Please check below URL for detail explanation.
https://medium.com/geekculture/upload-files-to-google-drive-with-c-c32d5c8a7abc
Regards,
Pasang
Vishal YelveRank #178 · 13.6K reputationPosted Jan 2, 2023, 7:25 AM EST
using Google.Apis.Auth.OAuth2; using Google.Apis.Drive.v3; using Google.Apis.Services; namespace DriveV3Snippets { // Class to demonstrate use of Drive insert file API public class UploadBasic { /// /// Upload new file. /// /// Image path to upload. /// Inserted file metadata if successful, null otherwise. public static string DriveUploadBasic(string filePath) { try { /* Load pre-authorized user credentials from the environment. TODO(developer) - See https://developers.google.com/identity for guides on implementing OAuth2 for your application. */ GoogleCredential credential = GoogleCredential.GetApplicationDefault() .CreateScoped(DriveService.Scope.Drive); // Create Drive API service. var service = new DriveService(new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = "Drive API Snippets" }); // Upload file photo.jpg on drive. var fileMetadata = new Google.Apis.Drive.v3.Data.File() { Name = "photo.jpg" }; FilesResource.CreateMediaUpload request; // Create a new file on drive. using (var stream = new FileStream(filePath, FileMode.Open)) { // Create a new file, with metadata and stream. request = service.Files.Create( fileMetadata, stream, "image/jpeg"); request.Fields = "id"; request.Upload(); } var file = request.ResponseBody; // Prints the uploaded file id. Console.WriteLine("File ID: " + file.Id); return file.Id; } catch (Exception e) { // TODO(developer) - handle error appropriately if (e is AggregateException) { Console.WriteLine("Credential Not found"); } else if (e is FileNotFoundException) { Console.WriteLine("File not found"); } else { throw; } } return null; } } }https://developers.google.com/drive/api/guides/manage-uploads#.net
https://www.daimto.com/upload-file-to-google-drive/