I have a base64 image that I am trying to save in a Postgres database (using Hasura). The field is of type bytea I am not sure how to save this data to the field.
I tried passing data:image/png;base64,sisodjodo... to the field, and it saves it like this: \x6956424f5277304b47676f414141414...
When I get it back it doesn't seem to come back in the same manner that it was saved.
// Query the database and save resulting object
const user = {
avatar: '\x6956424f5277304b47676f414141414...'
}
user.avatar = btoa(user.avatar);
console.log(user.avatar);
// Prints: XHg2OTU2NDI0ZjUyNzczMDRiNDc2NzZmNDE0MTQxNDE0Z...
btoa()is, it's not treating your'\x6956424f5277304b47676f41414141'as a binary. It is instead treating it like the string representation of\x6956424f5277304b47676f41414141. I don't do javascript since it's the devil's native tongue, but I was able to duplicate your output usingselect encode('\\x6956424f5277304b47676f41414141', 'base64');in a language not of darkness.text, notbytea, for a base64 encoded image.btoa()creates a Base64-encoded ASCII string from a binary string (i.e., a String object in which each character in the string is treated as a byte of binary data).