A problem has occurred recently when trying to upload files with the Google API dotnet client sdk. When the file name has any special Unicode characters, it throws an error.
Here is my code
public static Google.Apis.Drive.v2.Data.File InsertResource(Google.Apis.Drive.v2.DriveService service, string filePath, string parentId, string fileName, string mimeType)
{
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
try
{
// File's metadata.
body.Title = fileName;
body.MimeType = mimeType;
// Set the parent folder.
if (!String.IsNullOrEmpty(parentId))
{
var response = DriveUtils.GetFileInfo(service, parentId);
if (response.Error != null)
{
body.Error = response.Error;
return body;
}
body.Parents = new List<ParentReference>() { new ParentReference() { Id = parentId } };
}
byte[] byteArray = System.IO.File.ReadAllBytes(filePath);
MemoryStream stream = new MemoryStream(byteArray);
Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType);
request.Upload();
return request.ResponseBody;
}
catch (GoogleApiRequestException e)
{
body.Error = e.RequestError;
return body;
}
}
It was working fine up until this week. Any files that have chinese characters or turkish characters in the name will throw an error.
at Google.Apis.Json.JsonReader.ParseExpression(JsonToken token, TokenStream ts) at Google.Apis.Json.JsonReader.Parse(String jsonAsText) at Google.Apis.Upload.ResumableUpload`1.Upload()