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

Problem with convert images from file upload #3

Open
gintoni opened this issue Jun 13, 2019 · 2 comments
Open

Problem with convert images from file upload #3

gintoni opened this issue Jun 13, 2019 · 2 comments

Comments

@gintoni
Copy link

gintoni commented Jun 13, 2019

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

@Jeremy-coding
Copy link

Same problem.

@Jeremy-coding
Copy link

Jeremy-coding commented Sep 7, 2019

@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.

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