I’m having trouble uploading audio files to Google Drive using the Google Drive API in my .NET application. The upload process seems to run without throwing errors, but no file actually gets uploaded to my drive folder.
public async Task UploadAudioFileToDriveFolder(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 = googleDriveService.Files.Create(fileMetadata, fileStream, fileMetadata.MimeType);
var result = await uploadRequest.UploadAsync();
// This always comes back as null
var uploadedFileId = uploadRequest.ResponseBody?.Id;
Console.WriteLine($"Uploaded file ID: {uploadedFileId}");
}
catch (Exception error)
{
Console.WriteLine($"Upload failed: {error.Message}");
}
}
}
The method runs without exceptions but the ResponseBody property stays null and nothing shows up in my Google Drive. I’m working with the Google.Apis.Drive.v3 package in a UWP application. What could be causing this issue?
Had the same headache with Google Drive uploads. You’re probably missing the Execute() method after UploadAsync() to get the file metadata back. Try this:
var uploadRequest = googleDriveService.Files.Create(fileMetadata, fileStream, fileMetadata.MimeType);
var result = await uploadRequest.UploadAsync();
if (result.Status == Google.Apis.Upload.UploadStatus.Completed)
{
var uploadedFile = uploadRequest.ResponseBody;
Console.WriteLine($"Uploaded file ID: {uploadedFile?.Id}");
}
Also check your auth scope includes ‘https://www.googleapis.com/auth/drive.file’ or broader drive permissions. Without it, uploads might seem to work but fail silently. UWP can be weird with async operations too, so make sure you’re properly awaiting the calling method.
Check your Google Drive service setup first - I had the same problem and it was a config issue. Try dropping the mimetype parameter entirely and let Google figure it out automatically. Sometimes uploads work but you won’t see them until you refresh Drive or look in the root folder instead of where you expected them.
I hit this same issue before - it’s a MIME type problem. You’re using “application/vnd.google-apps.audio” which is Google’s native audio format, not for regular audio files. For standard audio files (MP3, WAV, etc.), use the actual MIME type like “audio/mpeg” or “audio/wav”. You can figure out the right MIME type from the file extension or just skip the MimeType parameter and let the API auto-detect it. Also, use uploadRequest.Upload() instead of UploadAsync() and check the result status. Even without exceptions, uploads can fail silently. The ResponseBody only gets populated after successful upload, so check the upload result status first to see what’s actually happening.