I try to draw an image (in base64 format) to a canvas in client-side JavaScript. There is unfortunately always the ERR_CONNECTION_RESET 431 (Request Header Fields Too Large)
error.
I get the base64 image as the response of an async POST request to a Node server. An example base64 image is:
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCA==='
but muuuuch longer obviously. The Chrome Dev console shows this:
GET http://localhost:3000/'data:image/png;base64,iVBORw0KGgoAA...
net::ERR_CONNECTION_RESET 431 (Request Header Fields Too Large)
Image (async)
(anonymous) @ client.js:59
async function (async)
(anonymous) @ client.js:51
My code is:
setInterval(async () => {
const post_options = {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(request)
}
const response = await fetch('/api', post_options)
const result = await response.json()
const base64_response = "'" + result['image64'] + "'"
const image = new Image()
image.onload = () => {
response_ctx.drawImage(image, 0, 0)
}
image.src = base64_response
}, 1000)
where canvas_ctx
is the canvas' 2d context and base64_response
is an image in the above specified format.
I should also mention that I am a newbie to JavaScript and Web Dev, as I only do it for a project of mine.
net::ERR_INVALID_URL
. The URL is justhttp://localhost:3000/data:image/png;base64,iVB...
then, do you know why that is invalid? – Rizzo