I have stored a base64url_encoded string into a postgres database by using binary data type in rails. Here is the migration
def change
add_column :gmail_attachments, :base64_data, :binary
end
The data I'm storing is coming as a base64 url encoded string from gmail API. When I tried to store the data as a string data type in postgres, I got
ArgumentError (string contains null byte)
So, I went with binary data type and it was stored successfully into database. Now, when I try
render status: 200, json: gmail_attachment_record
I get the following error
Encoding::UndefinedConversionError ("\xFF" from ASCII-8BIT to UTF-8):
How do I get rid of this error and return the stored data? Have I stored it in a wrong data type? What would be the best choice in rails ActiveRecord data types for achieving this?