ocr_space icon indicating copy to clipboard operation
ocr_space copied to clipboard

Problem with convert images from file upload

Open gintoni opened this issue 6 years ago • 2 comments

require 'ocr_space'

resource = OcrSpace::Resource.new(apikey: "MyApiKey")   #My actual api key

results = resource.clean_convert file: "/Users/Example/Desktop/image.jpg"  #the path is correct
puts results
Traceback (most recent call last):
        1: from ./ruby.rb:5:in `<main>'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/ocr_space-2.3.7/lib/ocr_space/convert.rb:33:in `clean_convert': undefined method `[]' for nil:NilClass (NoMethodError)

I've got some problems when I try to convert an image from file upload, but when I convert it from url it works perfectly

gintoni avatar Jun 13 '19 08:06 gintoni

Same problem.

Jeremy-coding avatar Sep 07 '19 11:09 Jeremy-coding

@gintoni if you want to post files to OcrSpace you can do it like this:

    res = HTTParty.post(
      'https://api.ocr.space/parse/image',
      body: {
        apikey: API_KEY,
        language: "eng",
        isOverlayRequired: true,
        file: File.new(Rails.root.join('public', 'test_files', 'tesla_quote.jpg').to_s)
      }
    )
    result = res.parsed_response['ParsedResults']

You don't even need the ocr_space gem, but you will need to have the HTTParty gem instead. Obviously substitute your own API key and file path into the File.new call.

Jeremy-coding avatar Sep 07 '19 12:09 Jeremy-coding