trouble with upload a png to ocr by javascript

  • 1.9K Views
  • Last Post 15 May 2012
longqjl posted this 14 May 2012

I use XMLHttpRequest to post a png file captured by canvas.
var xhr = new XMLHttpRequest(); xhr.send(canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, ""));

But the server replies me by "551 (Unsupported image file format)"

Vasily Panferov posted this 15 May 2012

Are you sure that replace() encodes your png image as base64?

var data = canvas.toDataURL('image/png');
data.replace(/^data:image\/(png|jpg);base64,/, "");

Also, it seems you are doing cross-domain XMLHttpRequest from within a browser. Take a look here. If you succeed in your task, let us know so we can add html/javascript sample to our samples repository.

Close