Answers for "json to base64 javascript using buffer"

1

convert json to base64 javascript

const json = { "a": 1, "b": 2 }
const string = JSON.stringify(json) // convert Object to a String
const encodedString = btoa(string) // Base64 encode the String
Posted by: Guest on June-02-2021
2

convert buffer to base64 javascript

var buffer = Buffer.from('hello');//create a buffer of the text "hello"
//right now, buffer == <Buffer 68 65 6c 6c 6f>
var string64 = buffer.toString('base64');
//the .toString operator can set encoding
//string64 == 'aGVsbG8='
Posted by: Guest on February-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language