我需要从列表中获取预设(System Presets)。如果我使用以下名称获取Preset,它将返回第一个Preset。但我需要将PresetId命名为“System preset:Generic 320x240”。
BasicAWSCredentials creds = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(creds)).build();
AmazonElasticTranscoder amazonElasticTranscoder = AmazonElasticTranscoderClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(creds)).withRegion(s3Client.getRegionName())
.build();
List<Preset> presets = amazonElasticTranscoder.listPresets().getPresets();
String presetId = presets.iterator().next().withName("System preset: Generic 320x240").getId();
以上代码返回“1351620000001-000001”而不是“1351620000001-000061”
我的pom.xml,
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.xxx.Application</start-class>
<java.version>1.8</java.version>
<aws.version>1.11.194</aws.version>
<aws.messaging.version>1.0.4</aws.messaging.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-elastictranscoder</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>${aws.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-sqs-java-messaging-lib</artifactId>
<version>${aws.messaging.version}</version>
</dependency>
我正在尝试从AWS Elastic Transcoder获取所有预设,但以下代码仅返回62个中的50个
List<Preset> presets = amazonElasticTranscoder.listPresets().getPresets();
如何使用java动态获取Preset? 如何获得所有预设(包括自定义预设)。
答案 0 :(得分:3)
我更熟悉Python SDK(而不是Java人员),但是这种行为看起来只是获得API调用结果的第一页(50个结果) - 您需要实现分页以获得所有结果
查看
PageToken
When Elastic Transcoder returns more than one page of results, use PageToken in subsequent GET requests to get each successive page of results.
和
NextPageToken
A value that you use to access the second and subsequent pages of results, if any. When the presets fit on one page or when you've reached the last page of results, the value of NextPageToken is null.
请参阅here
伪代码示例: 对listPresets()的初始调用应该得到NextPageToken,然后继续迭代请求,直到NextPageToken为null,同时将结果附加到局部变量。