代码之家  ›  专栏  ›  技术社区  ›  alopez02

通过Carrierwave上传时,获取一个AWS S3对象以用于Rekognition

  •  1
  • alopez02  · 技术社区  · 7 年前

    图像上传使用 Carrierwave gem fog-aws gem Amazon Rekognition .

    我已经安装了 aws-sdk gem 在调用 detect_labels

    我试过这么胖:

    @attachement = Attachment.first
    client = Aws::Rekognition::Client.new
    resp = client.detect_labels(
             image: @attachment
           )
    # I GET expected params[:image] to be a hash... and got class 'Attachment' instead
    

    我试过使用:

    client.detect_labels( image: { @attachment })
    client.detect_labels( image: { @attachment.content.url })
    client.detect_labels( image: { @attachment.content })
    

    检测标签

    我还尝试直接获取s3对象来尝试最后一位:

    s3 = AWS:S3:Client.new
    s3_object = s3.list_objects(bucket: 'my-bucket-name').contents[0]
    
    # and then
    
    client.detect_labels( image: { s3_object })
    

    有什么提示吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   alopez02    7 年前

    在以下几点的帮助下,我终于找到了问题所在 AWS forum

    “Image”散列键将一个必须命名为“s3\u object”的对象作为值,该对象随后只需要s3 bucket名称和要处理的文件的路径。作为参考,请参阅下面的正确示例:

    client = Aws::Rekognition::Client.new
    resp = client.detect_labels(
             image:
                { s3_object: {
                  bucket: "my-bucket-name",
                  name: @attachment.content.path, 
                },
              }
           )
    
    # @attachment.content.path => "uploads/my_picture.jpg"
    
    推荐文章