如何在Amzon Rekognition的Java程序中传递S3存储桶的子文件夹?

问题描述

这是演示程序

public class AddFacesToCollection {
public static final String collectionId = "MyCollection";
public static final String bucket = "bucket";
public static final String photo = "input.jpg";

public static void main(String[] args) throws Exception {

    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

    Image image = new Image()
            .withS3Object(new S3Object()
            .withBucket(bucket)
            .withName(photo));
    
    IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
            .withImage(image)
            .withQualityFilter(QualityFilter.AUTO)
            .withMaxFaces(1)
            .withCollectionId(collectionId)
            .withExternalImageId(photo)
            .withDetectionAttributes("DEFAULT");

    IndexFacesResult indexFacesResult = rekognitionClient.indexFaces(indexFacesRequest);
    
    System.out.println("Results for " + photo);

我想添加bucket的子文件夹的图像,例如bucketName / image / image1.jpg。我如何在Java中做到这一点。

解决方法

您应该使用:

  • Bucket=demo
  • Key=subfoldername/image1.jpg

也就是说,路径是对象名称的一部分,而不是存储桶名称。

根据您的代码:

.withBucket('demo')
.withName('subfoldername/image1.jpg'));