Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to upload image through node js #104

Open
TukaramKanade opened this issue Mar 15, 2018 · 1 comment
Open

How to upload image through node js #104

TukaramKanade opened this issue Mar 15, 2018 · 1 comment

Comments

@TukaramKanade
Copy link

Could you please provide the working example in node that will help me to upload the image .

I have tried with below code , but it is not working.

var bodyData = "-----BOUNDARY
Content-Type: application/json

{'engine':'tesseract'}
-----BOUNDARY

-----BOUNDARY
Content-Type: image/png
filename='attachment.txt'.

"+fs.createReadStream("E:\OCR\ocr_test.png")+"
-----BOUNDARY";

return new Promise(function (resolve, reject) {
    request({
        method: 'POST', 

        url: 'https://private-anon-63a2831b1f-openocr.apiary-mock.com/ocr-file-upload',
        headers: {
          'Content-Type': 'multipart/related; boundary=---BOUNDARY'
        },
        body : bodyData      
	},
    function(error, response, body){
        console.log('Status:', response.statusCode);
        console.log('Headers:', JSON.stringify(response.headers));
        console.log('Response:', body);

    	if(error)
    		reject(error)
    	else
	    	resolve(body)
    })

});	
@jazarja
Copy link

jazarja commented Apr 8, 2019

I use the following code to call openocr API

const metadata = {
        "engine": "tesseract",
        "engine_args": {
            "config_vars": {},
            "psm": "11",
            "lang": "ind+eng",
            "oem": "1",
        },
        "preprocessors": ["stroke-width-transform"]
    };

    return rp({
        method: 'POST',
        uri:  'http://your-hostname:9292/ocr-file-upload',
        multipart: [
            {
               'Content-Type': 'application/json',
                body: JSON.stringify(metadata)
            },
            {
                'Content-Type': 'image/png',
                'Content-Disposition' : 'attachment; filename="test.png"',
                body: fs.createReadStream(processedFilename)
            }
        ],
        timeout: 120000
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants