Skip to content

Commit 5784e07

Browse files
Add getLocation method to S3Resource. (awspring#611)
Fixes awspring#568
1 parent 2ae9b1b commit 5784e07

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

spring-cloud-aws-s3-parent/spring-cloud-aws-s3/src/main/java/io/awspring/cloud/s3/S3Resource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ public OutputStream getOutputStream() throws IOException {
166166
return s3OutputStreamProvider.create(location.getBucket(), location.getObject(), objectMetadata);
167167
}
168168

169+
public Location getLocation() {
170+
return location;
171+
}
172+
169173
private static class HeadMetadata {
170174

171175
private final Long contentLength;

spring-cloud-aws-s3-parent/spring-cloud-aws-s3/src/test/java/io/awspring/cloud/s3/S3ResourceIntegrationTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ void retrievesMetadata() {
240240
.containsEntry("camelcasekey", "camelCaseKeyValue").doesNotContainKey("camelCaseKey");
241241
}
242242

243+
@Test
244+
void returnsLocationObject() {
245+
S3Resource resource = s3Resource("s3://first-bucket/new-file.txt",
246+
new InMemoryBufferingS3OutputStreamProvider(client, new PropertiesS3ObjectContentTypeResolver()));
247+
Location location = resource.getLocation();
248+
assertThat(location).isNotNull();
249+
assertThat(location.getBucket()).isEqualTo("first-bucket");
250+
assertThat(location.getObject()).isEqualTo("new-file.txt");
251+
}
252+
243253
@NotNull
244254
private S3Resource s3Resource(String location, S3OutputStreamProvider s3OutputStreamProvider) {
245255
return new S3Resource(location, client, s3OutputStreamProvider);

0 commit comments

Comments
 (0)