software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest Java Examples

The following examples show how to use software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: S3Manager.java    From joyqueue with Apache License 2.0 9 votes vote down vote up
private String getS3Url(String objectKey) {
    AwsCredentialsProvider credentialsProvider = StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey));
    S3Presigner preSigner = S3Presigner.builder()
            .credentialsProvider(credentialsProvider)
            .endpointOverride(URI.create(endpoint))
            .region(clientRegion).build();
    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
            .bucket(bucketName)
            .key(objectKey)
            .build();
    GetObjectPresignRequest getObjectPresignRequest = GetObjectPresignRequest.builder()
            .getObjectRequest(getObjectRequest).signatureDuration(Duration.ofDays(7)).build();
    PresignedGetObjectRequest presignedGetObjectRequest = preSigner.presignGetObject(getObjectPresignRequest);
    String url = presignedGetObjectRequest.url().toString();
    preSigner.close();
    return url;
}
 
Example #2
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public PresignedGetObjectRequest presignGetObject(GetObjectPresignRequest request) {
    return presign(PresignedGetObjectRequest.builder(),
                   request,
                   request.getObjectRequest(),
                   GetObjectRequest.class,
                   getObjectRequestMarshaller::marshall,
                   "GetObject")
        .build();
}
 
Example #3
Source File: S3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 2 votes vote down vote up
/**
 * Presign a {@link GetObjectRequest} so that it can be executed at a later time without requiring additional
 * signing or authentication.
 * <p/>
 *
 * <b>Example Usage</b>
 * <p/>
 *
 * <pre>
 * {@code
 *     S3Presigner presigner = ...;
 *
 *     // Create a GetObjectRequest to be pre-signed
 *     GetObjectRequest getObjectRequest = ...;
 *
 *     // Create a GetObjectPresignRequest to specify the signature duration
 *     GetObjectPresignRequest getObjectPresignRequest =
 *         GetObjectPresignRequest.builder()
 *                                .signatureDuration(Duration.ofMinutes(10))
 *                                .getObjectRequest(request)
 *                                .build();
 *
 *     // Generate the presigned request
 *     PresignedGetObjectRequest presignedGetObjectRequest =
 *         presigner.presignGetObject(getObjectPresignRequest);
 *
 *     if (presignedGetObjectRequest.isBrowserExecutable())
 *         System.out.println("The pre-signed request can be executed using a web browser by " +
 *                            "visiting the following URL: " + presignedGetObjectRequest.url());
 *     else
 *         System.out.println("The pre-signed request has an HTTP method, headers or a payload " +
 *                            "that prohibits it from being executed by a web browser. See the S3Presigner " +
 *                            "class-level documentation for an example of how to execute this pre-signed " +
 *                            "request from Java code.");
 * }
 * </pre>
 */
PresignedGetObjectRequest presignGetObject(GetObjectPresignRequest request);
 
Example #4
Source File: S3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 2 votes vote down vote up
/**
 * Presign a {@link GetObjectRequest} so that it can be executed at a later time without requiring additional
 * signing or authentication.
 * <p />
 * This is a shorter method of invoking {@link #presignGetObject(GetObjectPresignRequest)} without needing
 * to call {@code GetObjectPresignRequest.builder()} or {@code .build()}.
 * 
 * @see #presignGetObject(GetObjectPresignRequest)
 */
default PresignedGetObjectRequest presignGetObject(Consumer<GetObjectPresignRequest.Builder> request) {
    GetObjectPresignRequest.Builder builder = GetObjectPresignRequest.builder();
    request.accept(builder);
    return presignGetObject(builder.build());
}