Я пытаюсь интегрировать AWS Rekognition в мое приложение Rails.После того, как пользователь загрузит свой аватар через Active Storage, Rekognition должен показать некоторую информацию об этом.
def update
respond_to do |format|
if @user.update(user_params)
if @user.images.attached?
Aws.config.update({
region: 'us-west-2',
credentials: Aws::Credentials.new('ACCESS_KEY', 'SECRET_KEY')
})
rekognition = Aws::Rekognition::Client.new(region: Aws.config[:region], credentials: Aws.config[:credentials])
img = @user.images.first. # original was: File.read(ARGV.first)
#detect faces
resp = rekognition.detect_faces({
image: { bytes: img },
attributes: ["ALL"], # What attributes to return
})
resp.face_details[0].emotions.each do |emo|
puts emo.type + " " + emo.confidence.to_i.to_s #=> Strings "HAPPY", "SAD", "ANGRY"
end
end
end
end
Однако я получаю ошибку
expected params[:image][:bytes] to be a String or IO object, got value #<ActiveStorage::Attachment id: 4, name: "images", record_type: "User", record_id: 47, blob_id: 9, created_at: ""> (class: ActiveStorage::Attachment) instead.
Как можноЯ получаю свойство файла изображения в AWS Rekognition?