File upload to Google Drive not working with .NET Drive API v3

I’m having trouble uploading audio files to Google Drive using the Google Drive API v3 in my .NET application. The upload method runs without throwing errors, but no file appears in my Drive folder and the response comes back as null.

Here’s the code I’m using:

public async Task UploadAudioFile(StorageFile audioFile, string targetFolder)
{
    if (audioFile == null) return;
    
    string parentFolderId = await FindFolderByName(targetFolder);
    if (string.IsNullOrEmpty(parentFolderId)) return;
    
    var fileMetadata = new Google.Apis.Drive.v3.Data.File
    {
        Name = audioFile.Name,
        Parents = new List<string> { parentFolderId },
        MimeType = "application/vnd.google-apps.audio"
    };
    
    using (var fileStream = await audioFile.OpenStreamForReadAsync())
    {
        try
        {
            var uploadRequest = driveService.Files.Create(fileMetadata, fileStream, fileMetadata.MimeType);
            var result = await uploadRequest.UploadAsync();
            
            if (uploadRequest.ResponseBody != null)
            {
                Debug.WriteLine($"File uploaded: {uploadRequest.ResponseBody.Id}");
            }
            else
            {
                Debug.WriteLine("Upload failed - response is null");
            }
        }
        catch (Exception error)
        {
            Debug.WriteLine($"Error during upload: {error.Message}");
        }
    }
}

The ResponseBody property always returns null even though no exceptions are thrown. I’m using the Google.Apis.Drive.v3 package in a UWP application. What could be causing this issue?

Been wrestling with Drive API uploads for years and this screams classic status-checking issue. ResponseBody being null doesn’t mean the upload failed - check result.Status and result.Exception from your UploadAsync call instead. I’ve seen files upload successfully while ResponseBody stays null because of timing issues or partial completion states. Add Debug.WriteLine($"Upload status: {result.Status}"); right after the upload call. If it shows Completed, your file probably uploaded but you can’t see it because of folder permissions or FindFolderByName returning the wrong folder ID. UWP also has stream handling quirks - make sure your StorageFile stream isn’t getting disposed too early.

Had this exact problem six months ago and wasted hours debugging it. Your MIME type’s wrong. application/vnd.google-apps.audio is for Google’s internal audio format, not regular file uploads. Use the actual MIME type instead: audio/mpeg for MP3s, audio/wav for WAV files, or audio/ogg for OGG. You can check the file extension or use a library to detect it automatically. Also verify result.Status shows UploadStatus.Completed before assuming it worked. The API returns null ResponseBody even when uploads partially complete but fail Google’s validation due to wrong MIME types. Fixed the MIME type in my project and ResponseBody started returning the file ID properly.

check your auth scopes first - if you’re only using readonly, uploads will silently fail. you need https://www.googleapis.com/auth/drive.file or https://www.googleapis.com/auth/drive in your credentials. also try uploadRequest.Upload() instead of uploadAsync() to see if it behaves differently.