use of software.amazon.awssdk.services.s3.presigner.model.PresignedUploadPartRequest in project formkiq-core by formkiq.
the class S3Service method presignPostUrl.
/**
* Generate a S3 Signed Url for creating an object using POST request.
*
* @param bucket {@link String}
* @param key {@link String}
* @param duration {@link Duration}
* @param contentLength {@link Optional} {@link Long}
* @return {@link URL}
*/
public URL presignPostUrl(final String bucket, final String key, final Duration duration, final Optional<Long> contentLength) {
try (S3Presigner signer = this.builder.buildPresigner()) {
UploadPartRequest.Builder uploadBuilder = UploadPartRequest.builder().bucket(bucket).key(key);
if (contentLength.isPresent()) {
uploadBuilder = uploadBuilder.contentLength(contentLength.get());
}
UploadPartPresignRequest prereq = UploadPartPresignRequest.builder().signatureDuration(duration).uploadPartRequest(uploadBuilder.build()).build();
PresignedUploadPartRequest req = signer.presignUploadPart(prereq);
return req.url();
}
}
use of software.amazon.awssdk.services.s3.presigner.model.PresignedUploadPartRequest in project aws-sdk-java-v2 by aws.
the class S3PresignerIntegrationTest method uploadPart_CanBePresigned.
@Test
public void uploadPart_CanBePresigned() throws IOException {
String objectKey = generateRandomObjectKey();
S3TestUtils.addCleanupTask(S3PresignerIntegrationTest.class, () -> client.deleteObject(r -> r.bucket(testBucket).key(objectKey)));
CreateMultipartUploadResponse create = client.createMultipartUpload(createMultipartUploadRequest(objectKey));
S3TestUtils.addCleanupTask(S3PresignerIntegrationTest.class, () -> client.abortMultipartUpload(abortMultipartUploadRequest(objectKey, create.uploadId())));
PresignedUploadPartRequest uploadPart = presigner.presignUploadPart(up -> up.signatureDuration(Duration.ofDays(1)).uploadPartRequest(upr -> upr.bucket(testBucket).key(objectKey).partNumber(1).uploadId(create.uploadId())));
HttpExecuteResponse uploadPartResponse = execute(uploadPart, testObjectContent);
assertThat(uploadPartResponse.httpResponse().isSuccessful()).isTrue();
String etag = uploadPartResponse.httpResponse().firstMatchingHeader("ETag").orElse(null);
client.completeMultipartUpload(createMultipartUploadRequest(objectKey, create, etag));
String content = client.getObjectAsBytes(r -> r.bucket(testBucket).key(objectKey)).asUtf8String();
assertThat(content).isEqualTo(testObjectContent);
}
Aggregations