0

I'm in the process of building an Ionic 2 (ts) app that will send a REST call to the OCR.space API. Going through their examples, I'm able to send a a Base64Image via HTTP.post, but when attempting to send a file via HTTP.Post, I'm met with:

{"ParsedResults":null,"OCRExitCode":0,"IsErroredOnProcessing":false,"ErrorMessage":["Parameter
        name 'file' is invalid. Valid parameters:
        apikey,url,language,isoverlayrequired,base64image"],"ErrorDetails":null,"ProcessingTimeInMilliseconds":"1"}

I'm guessing it's my formatting of my post request:

        HTTP.post('http://api.ocr.space/parse/image',
    { "apikey":"helloworld", "language":"eng", "isOverlayRequired":"false", "file": "asssets/img/test2.pdf" }, {})
      .then(data => {
        console.log("HTTP entered");
        let result = JSON.parse(data.data); // data received by server
        console.log(data.data);
      })
      .catch(error => {
        console.log(error.error); // error message as string
      });

And I'm guessing this because I'm able to send PDF files successfully via postman like below: my successful postman request

So - I'd love some help figuring out how to send this HTTP.post request successfully or convert the code I can get from postman to successful ionic-native syntax.

    var form = new FormData();
form.append("apikey", "541496f13e88957");
form.append("language", "eng");
form.append("isOverlayRequired", "false");
form.append("file", "1page.pdf");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://api.ocr.space/parse/image",
  "method": "POST",
  "headers": {
    "cache-control": "no-cache",
    "postman-token": "1aea47d5-a0eb-7768-5fa6-60c4cd76d453"
  },
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

I appreciate any and all help!

  • What is the error message you get? Where does it not work? In the browser when testing with `ionic serve` or on a device? – NoNameProvided Feb 16 '17 at 21:09
  • The error message is in the first code block inside the json - the API call is working - i get a response - but i think my formatting of the response is off and the API doesn't understand my request. "ErrorMessage":["Parameter name 'file' is invalid. Valid parameters: apikey,url,language,isoverlayrequired,base64image" But the docs clearly states that file is a valid param. – Devin Santamaria Feb 16 '17 at 21:32

1 Answers1

0

I'm using cordova-plugin-file-transfer to send file instead of Base64Image or for Ionic 2 using ionic-native with the examples

Djamware
  • 126
  • 1
  • 7