Skip to content

FS.writeFile is writing incorrect data when passed a string containing binary data. #22056

Closed Answered by 98ahni
98ahni asked this question in Q&A
Discussion options

You must be logged in to vote

This seems to be one of many oversights from Google and the documentation they provide. The "body" is a File blob according to the docs. It does not specify how to choose whether it's represented as a string or an ArrayBuffer, just that you can. Apparently, this is set in the Google.drive() constructor which doesn't exist in the JS version of the api. The discussions I could find for fixing this ended with one dev team blaming another.
Sorry for the mini rant, on to my "solution".

I managed to brute-force it by looping over the string, getting each char and then passing that to a Uint8Array.

const res = await gapi.client.drive.files.get({
    'fileId': file.id,
    'alt': 'media'
});
var b…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@98ahni
Comment options

@sbc100
Comment options

@98ahni
Comment options

@sbc100
Comment options

@98ahni
Comment options

Comment options

You must be logged in to vote
1 reply
@sbc100
Comment options

Answer selected by 98ahni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants