Gibberish returned from gapi.client.drive.files.get() using alt: 'media' if content includes non-English (charset?) letters
thexs-dev opened this issue · 1 comments
I am using the following code to get the content of a text file uploaded (plain text with MimeType.JAVASCRIPT) to Google Drive.
let response = await gapi.client.drive.files.get({
'fileId': "google-drive-file-id-goes-here", alt: 'media'
});
let content = response.body;
It gets the actual content in Google Drive if the content only includes English (charset?) letters
- But if the file has other letters, the content shows them as gibberish instead
See example below for the word Pharmacy in other languages and what the content is showing between ()
- Hebrew: בית מרקחת (× × ×ª × ×¨×§× ×ª)
- Japanese 薬局 (è ¬å±)
- Arabic: مقابل (٠٠ابÙ)
How to fix this issue using the gapi.client.drive.files.get() function?
Thanks in advance for your support on this
Fausto
There is what I would consider a bug in the /drive/v3/files/${fileID} endpoint that's hit when calling drive.files.get or drive.files.export in that the server is always returning a Content-Type of "text/plain;charset=UTF-8". This Stack Overflow answer, https://stackoverflow.com/a/63818644/1075909, explains how to work around this. Other related SO post, https://stackoverflow.com/questions/66799006/unwanted-content-type-text-plaincharset-utf-8-header-in-google-drive-api-res