2

我只是在尝试一些新技术并了解有关 abbyy gem我在http://ocrsdk.com/plans-and-pricing/上创建了一个免费帐户

我正在按照宝石上的说明进行操作

class Client < ActiveRecord::Base
  def abbyy
    client = Abbyy::Client.new
    client.process_business_card self.business_card, exportFormat: 'xml', imageSource: 'photo'
    # Errno::ENOENT: No such file or directory - https://appname-dev.s3.amazonaws.com/uploads/client/business_card/1/bizcard.jpg
    client.get_task_status
    client.get
  end
end

但我收到了这个错误

Errno::ENOENT:没有这样的文件或目录 - https://appname-dev.s3.amazonaws.com/uploads/client/business_card/1/bizcard.jpg

我确保我上传的目录是公开的

这是演示应用程序的链接https://github.com/mzaragoza/abbyy

4

1 回答 1

3

添加require 'open-uri'到文件的顶部。

然后下载文件,然后才交给abby:

def abby
  require 'tempfile'
  card = Tempfile.new('business_card')
  card.binmode
  stream = open(self.business_card.url)
  card.write(stream.read)
  stream.close
  card.close
  client = Abbyy::Client.new
  client.process_business_card card.path, exportFormat: 'xml', imageSource: 'photo'
  client.get_task_status
  client.get
ensure
  # ensuring every handle is closed, and ignoring exceptions, which could arise if handles already closed
  # or haven't been opened
  stream.close rescue nil
  card.close rescue nil
  card.unlink rescue nil
end
于 2015-08-02T14:33:39.323 回答