Created
February 16, 2013 21:12
-
-
Save leggetter/4968764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var fs = require( 'fs' ); | |
var path = require('path'); | |
var WS_URL = 'http://api.ocrapiservice.com/1.0/rest/ocr'; | |
SO2(); | |
function SO2() { | |
var base64Str = fs.readFileSync( 'example.png' ).toString( 'base64' ); | |
var buffer = new Buffer(base64Str, 'base64'); | |
ocr( buffer.toString( 'binary' ) ); | |
} | |
function ocr( postData, header ) { | |
var r = request.post(WS_URL, completed); | |
var form = r.form(); | |
// filename="example.png"\r\nContent-Type: image/png\r\n\r\n' | |
var options = null; | |
if( header ) { | |
options = { | |
header: CRLF + '--' + form.getBoundary() + CRLF + header + CRLF + CRLF | |
}; | |
} | |
form.append('apikey', 'REMOVED'); | |
form.append('language', 'en' ); | |
form.append('image', postData, options ); | |
function completed(error, response, body) { | |
console.log( body ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment