How to upload local images to a new Google Drive folder using C# .NET?

Hey everyone! I’m working on a desktop app using C# .NET and I’m trying to figure out how to use the Google Drive API. My goal is to create a new folder in Google Drive and then upload some image files from my computer to that folder. I’m pretty new to working with Google Drive, so any help or guidance would be really appreciated. Has anyone done something similar before? What are the key steps I need to follow? Thanks in advance for any tips or code examples you can share!

I tackled a similar project recently using C# .NET and the Google Drive API. I began by setting up OAuth 2.0 credentials and installing the Google.Apis.Drive.v3 NuGet package. The next step was to initialize the DriveService with the proper credentials. I then created a new folder by using Files.Create with the necessary metadata to indicate that it was a folder. Once I had the folder ID, I uploaded the image files by calling Files.Create again with the upload type set to media, ensuring that I set the parents property correctly. Error handling and retry logic played a key role in maintaining robustness, and I used FileDataStore to manage token persistence. Thorough testing, especially with varying file sizes and network speeds, is essential for a dependable implementation.

hey there! i’ve done this before. quick tip: use google.apis.drive.v3 nuget package. create driveservice with ur credentials, then use files.create to make folder. for uploading, use files.create again with uploadtype=‘media’. don’t forget to set parents property to new folder ID. goodluck!

I’ve actually implemented something similar in a project recently. Here’s what worked for me:

First, you’ll need to set up OAuth 2.0 credentials and install the Google.Apis.Drive.v3 NuGet package. Then, create a DriveService instance using your credentials.

To create a folder, use the Files.Create method with metadata specifying it’s a folder. Store the returned folder ID.

For uploading images, you can use Files.Create again, but this time set the uploadType parameter to ‘media’ and provide the file stream. Make sure to set the parents property in the file metadata to your new folder’s ID.

One tricky part was handling token refresh - I’d recommend using a FileDataStore to persist the token between runs.

Remember to handle potential API errors and implement retry logic for more robust uploads. Good luck with your project!