Amazon Elastic Transcoder - 如何使用名称获取预设

问题描述 投票:4回答:1

我需要从列表中获取预设(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”

我们理解。

        <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?如何获取所有预设(包括自定义预设)。

java amazon-web-services amazon-s3 amazon-elastic-transcoder
1个回答
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,同时将结果附加到局部变量。

© www.soinside.com 2019 - 2024. All rights reserved.