Java Code Examples for com.amazonaws.services.s3.model.PutObjectRequest#getMetadata()
The following examples show how to use
com.amazonaws.services.s3.model.PutObjectRequest#getMetadata() .
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: S3Archiver.java From chancery with Apache License 2.0 | 6 votes |
private void upload(@NotNull File src, @NotNull String key, @NotNull CallbackPayload payload) { log.info("Uploading {} to {} in {}", src, key, bucketName); final PutObjectRequest request = new PutObjectRequest(bucketName, key, src); final ObjectMetadata metadata = request.getMetadata(); final String commitId = payload.getAfter(); if (commitId != null) { metadata.addUserMetadata("commit-id", commitId); } final DateTime timestamp = payload.getTimestamp(); if (timestamp != null) { metadata.addUserMetadata("hook-timestamp", ISODateTimeFormat.basicTime().print(timestamp)); } final TimerContext time = uploadTimer.time(); try { s3Client.putObject(request); } catch (Exception e) { log.error("Couldn't upload to {} in {}", key, bucketName, e); throw e; } finally { time.stop(); } log.info("Uploaded to {} in {}", key, bucketName); }
Example 2
Source File: AmazonS3SinkMockTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Test @Override public void test() throws Exception { AmazonS3 amazonS3Client = TestUtils.getPropertyValue(this.s3MessageHandler, "transferManager.s3", AmazonS3.class); InputStream payload = new StringInputStream("a"); Message<?> message = MessageBuilder.withPayload(payload) .setHeader("key", "myInputStream") .build(); this.channels.input().send(message); ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); verify(amazonS3Client, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture()); PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue(); assertThat(putObjectRequest.getBucketName(), equalTo(S3_BUCKET)); assertThat(putObjectRequest.getKey(), equalTo("myInputStream")); assertNull(putObjectRequest.getFile()); assertNotNull(putObjectRequest.getInputStream()); ObjectMetadata metadata = putObjectRequest.getMetadata(); assertThat(metadata.getContentMD5(), equalTo(Md5Utils.md5AsBase64(payload))); assertThat(metadata.getContentLength(), equalTo(1L)); assertThat(metadata.getContentType(), equalTo(MediaType.APPLICATION_JSON_VALUE)); assertThat(metadata.getContentDisposition(), equalTo("test.json")); }
Example 3
Source File: TestPutS3Object.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testFilenameWithNationalCharacters() throws UnsupportedEncodingException { prepareTest("Iñtërnâtiônàližætiøn.txt"); runner.run(1); ArgumentCaptor<PutObjectRequest> captureRequest = ArgumentCaptor.forClass(PutObjectRequest.class); Mockito.verify(mockS3Client, Mockito.times(1)).putObject(captureRequest.capture()); PutObjectRequest request = captureRequest.getValue(); ObjectMetadata objectMetadata = request.getMetadata(); assertEquals("Iñtërnâtiônàližætiøn.txt", URLDecoder.decode(objectMetadata.getContentDisposition(), "UTF-8")); }
Example 4
Source File: AmazonS3SinkMockTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 4 votes |
@Test @Override public void test() throws Exception { AmazonS3 amazonS3Client = TestUtils.getPropertyValue(this.s3MessageHandler, "transferManager.s3", AmazonS3.class); File file = this.temporaryFolder.newFile("foo.mp3"); Message<?> message = MessageBuilder.withPayload(file) .build(); this.channels.input().send(message); ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class); verify(amazonS3Client, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture()); PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue(); assertThat(putObjectRequest.getBucketName(), equalTo(S3_BUCKET)); assertThat(putObjectRequest.getKey(), equalTo("foo.mp3")); assertNotNull(putObjectRequest.getFile()); assertNull(putObjectRequest.getInputStream()); ObjectMetadata metadata = putObjectRequest.getMetadata(); assertThat(metadata.getContentMD5(), equalTo(Md5Utils.md5AsBase64(file))); assertThat(metadata.getContentLength(), equalTo(0L)); assertThat(metadata.getContentType(), equalTo("audio/mpeg")); ProgressListener listener = putObjectRequest.getGeneralProgressListener(); S3ProgressPublisher.publishProgress(listener, ProgressEventType.TRANSFER_COMPLETED_EVENT); assertTrue(this.transferCompletedLatch.await(10, TimeUnit.SECONDS)); assertTrue(this.aclLatch.await(10, TimeUnit.SECONDS)); ArgumentCaptor<SetObjectAclRequest> setObjectAclRequestArgumentCaptor = ArgumentCaptor.forClass(SetObjectAclRequest.class); verify(amazonS3Client).setObjectAcl(setObjectAclRequestArgumentCaptor.capture()); SetObjectAclRequest setObjectAclRequest = setObjectAclRequestArgumentCaptor.getValue(); assertThat(setObjectAclRequest.getBucketName(), equalTo(S3_BUCKET)); assertThat(setObjectAclRequest.getKey(), equalTo("foo.mp3")); assertNull(setObjectAclRequest.getAcl()); assertThat(setObjectAclRequest.getCannedAcl(), equalTo(CannedAccessControlList.PublicReadWrite)); }