I am attempting to convert a Base64 image string in a JavaScript Chrome extension. I have gotten the request to work in Postman. However I am getting this error when request is implemented in code:
error TypeError: Failed to execute ‘fetch’ on ‘WorkerGlobalScope’: Request with GET/HEAD method cannot have body.
This error also occurs when using the code provided by Postman. According to the Mozilla docs the HTTP GET method should not have a body. However it seems like the OCR Space API only supports submitting the base64 string in a body for the GET method. Using it as a param results in a “URL too long” error.
Also, the curl request from this OCR Space Blog also does not work.
I haven’t seen anyone online or on this forum figure this issue out yet. Could someone please clarify how this works?
Here is my working request on Postman:
Endpoint:
https://api.ocr.space/parse/imageurl?language=eng&isOverlayRequired=false&OCREngine=2
Params:
language, isOverlayRequired, OCREngine
Headers:
apikey
Body:
base64image
I’ve tried this with all the example URLs as well
Here is the code provided by Postman that still does not work:
var myHeaders = new Headers()
myHeaders.append(“apikey”, apiKey)
var formdata = new FormData()
formdata.append(“base64image”, imageBase64)
var requestOptions = {
method: “GET”,
headers: myHeaders,
body: formdata,
redirect: “follow”,
}
fetch(
“endpoint (forum wont allow me to put in more than 2 links)”,
requestOptions
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log(“error”, error))
}