How to post file with nodejs?

  • 3.5K Views
  • Last Post 20 August 2012
log0div0 posted this 18 August 2012

I use request module to make post request (Coffeescript):

request
    method: 'POST'
    uri: "http://cloud.ocrsdk.com/processImage"
    headers:
        Authorization: 'Basic: ' + new Buffer("#{id}:#{password}").toString 'base64'
    qs:
        language: 'russian'
        imageSource: 'scanner'
        exportFormat: 'xml'
    body: file_content
But I get response 551 "Unsupported image file format". How I must send file? How your server know, which format file have? Must I specify file format anywhere? How must http package look like?

I learn samples (.net and python), watch traffic with WireShark, and try to do the same on nodejs, but it does not work.

Order By: Standard | Newest | Votes
log0div0 posted this 19 August 2012

Problem solved. file_content must be a Buffer object, not String.

  • Liked by
  • Dmitry Me
Vasily Panferov posted this 20 August 2012

You can also take a look at a third-party library in coffeescript to access cloud ocr sdk: https://github.com/selead/node-ocr

  • Liked by
  • Dmitry Me
  • log0div0
Close