2
votes

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?

1
No one ever used TypeORM with blob columns?Ralf Schneider
Yes, only your question helped me find it, years later. Tell me if you find any better technique than this.Rahul Bali
No, but to be honest, I did not search for an alternative solution :-)Ralf Schneider

1 Answers

2
votes

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');