I want to fake a response. I have the base64 string data of a png
image. Now I want to make a response but It does not work.
My code:
const data = "data:image/png;base64,iVBORw0KGgoAAAA...";
const res = new Response(data, {
status: 200,
statusText: "OK",
headers: {
"Content-Type": "image/png",
"Content-Length": data.length
},
});
I did some research, and it seems like base64
can not just be passed to response body. It needs to be converted to a buffer or something like that.
It can be done in NodeJS like this Buffer.from(data, 'base64')
But my code is in the browser only.
Is there any way that I can implement this.