question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I read a Base64 Url encoded string to excel?

See original GitHub issue

I’m getting a xlsx attachment using the Gmail API https://developers.google.com/gmail/api/v1/reference/users/messages/attachments#resource

It returns it as a “The body data of a MIME message part as a base64url encoded string.”

I’m not sure how to read it?

XLSX.read(attachment, {type: 'base64'});

I get

TypeError: f.substr is not a function

How I do read this? Ultimately I want to convert that base64 format from Gmail to a JSON object.

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
Mujtaba4ahmedcommented, Feb 14, 2018

I have an XLSX file on the server which I am trying to download. When I hit that url with axios call, I get very diff, random data as response. How do I convert it to normal xlsx data?

data : &��\���ad,��J������]bl��sM�E@�&ŵ�ͧ 0�� b�TC%̔J ba���4���8’��8 oA��YRi ڨV�ߌ�,1/hK8�� K6�+�,�!��D���p�k�%���:v ��h’�T�)�!���c�O�j|�G�Q{����U�pb�n’(��!�R-W0@����W��0��u�I��;�YᲨ�ok>N0YЎ)����=�� Ç��W��/X�\�ZtZ�O�,ᴴ�YU��U����U���JI�]���’�M�b[��� i�Od

Data from response looks like this.

1reaction
louckoussecommented, Aug 7, 2019

I had this problem and what I did was:

const buf = Buffer.from(attachment, 'base64')
const sheet = xlsx.read(buf, { type: 'buffer' })

I get the same result that with the replace but I find it cleaner for reading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ENCODEURL: Excel Formulae Explained - Causal
The function takes two arguments: the text string to encode and the encoding type. The encoding type can be either "url" or "base64"....
Read more >
Base64 Encoding of "excel" - Online
Simply enter your data then push the encode button. ... Encode each line separately (useful for when you have multiple entries). Split lines...
Read more >
How do I base64 encode a string efficiently using Excel VBA?
You can use the MSXML Base64 encoding functionality as described at www.nonhostile.com/howto-encode-decode-base64-vb6.asp: Function EncodeBase64(text As ...
Read more >
ENCODEURL function - Microsoft Support
The ENCODEURL function returns a URL-encoded string, replacing certain non-alphanumeric characters with the percentage symbol (%) and a hexadecimal number.
Read more >
Base64UrlEncoder Class (Microsoft.IdentityModel.Tokens)
Decode(String). Decodes the string from Base64UrlEncoded to UTF8. ; DecodeBytes(String). Converts the specified string, base-64-url encoded to utf8 bytes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found