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?