I have a MySQL database that stores profile images of users. The user info should be provided via REST API that is implemented as a Node.js server. I use TypeORM for accessing the database.
I want to deliver the image info as base64 string via REST API. How could I achieve this?
I mapped the blob column as a Buffer in my entity. Do I have to convert the data to base64 using a listener on the property?
I found the solution that works for me:
I load the user object and the image is loaded into a string variable. Before I deliver the object I convert it into a Buffer and encode it base64:
Buffer.from(user.profileImage).toString('base64');