ocr_space
ocr_space copied to clipboard
Problem with convert images from file upload
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
Same problem.
@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.