f2calv / CasCap.Apis.GooglePhotos

*unofficial* Google Photos REST API library for .NET projects.
MIT License
58 stars 10 forks source link

Uploading of files with names containing non-English characters is not supported #110

Closed Belfegor1991 closed 1 year ago

Belfegor1991 commented 1 year ago

Sometimes when uploading files with names that contain non-English characters fails. For example, uploading of file a "D:\2003.02.06 - (Открытый) Урок английского.jpg" fails and the server returns an HTML page

Error 400 (Bad Request)!!1

which eventually results in Newtonsoft.Json.JsonReaderException

Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

The reason for this is the HTTP standard that doesn't support non-ISO-8859-1 characters directly in an HTTP header. Thus characters should be encoded to be passed in the header.

Suggested fix: use HttpUtility.UrlPathEncode in GooglePhotosServiceBase.UploadMediaAsync:

headers.Add((X_Goog_Upload_File_Name, HttpUtility.UrlPathEncode(Path.GetFileName(path))));

f2calv commented 1 year ago

Thanks for the alert+fix.

A little concerning that the docs for HttpUtility.UrlPathEncode say Do not use ...however it seems to work fine and I don't see any downside to implement this.

I hope to roll this fix out in the next couple of days as part of https://github.com/f2calv/CasCap.Apis.GooglePhotos/pull/112