Skip to content

Commit 952f6b4

Browse files
committed
Fixes #183
1 parent 1ffa3ec commit 952f6b4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

server/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@
194194
<artifactId>hypersistence-utils-hibernate-63</artifactId>
195195
<version>3.10.3</version>
196196
</dependency>
197+
<dependency>
198+
<groupId>net.coobird</groupId>
199+
<artifactId>thumbnailator</artifactId>
200+
<version>0.4.20</version>
201+
</dependency>
197202
<dependency>
198203
<groupId>org.wiremock</groupId>
199204
<artifactId>wiremock-standalone</artifactId>

server/src/main/java/access/api/S3Storage.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import lombok.SneakyThrows;
5+
import net.coobird.thumbnailator.Thumbnails;
56
import org.springframework.beans.factory.annotation.Value;
67
import org.springframework.stereotype.Service;
78
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
@@ -14,6 +15,8 @@
1415
import software.amazon.awssdk.services.s3.model.*;
1516

1617
import java.io.ByteArrayInputStream;
18+
import java.io.ByteArrayOutputStream;
19+
import java.io.InputStream;
1720
import java.net.URI;
1821
import java.util.Base64;
1922
import java.util.List;
@@ -56,6 +59,7 @@ public S3Storage(@Value("${s3storage.url}") String s3URL,
5659
this.objectMapper = objectMapper;
5760
}
5861

62+
@SneakyThrows
5963
public String uploadFile(String content) {
6064
byte[] decodedBytes = Base64.getDecoder().decode(content);
6165

@@ -64,6 +68,14 @@ public String uploadFile(String content) {
6468
}
6569

6670
ByteArrayInputStream inputStream = new ByteArrayInputStream(decodedBytes);
71+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
72+
Thumbnails.of(inputStream)
73+
.size(200, 200)
74+
.keepAspectRatio(true)
75+
.toOutputStream(baos);
76+
77+
inputStream = new ByteArrayInputStream(baos.toByteArray());
78+
6779
String uuid = UUID.randomUUID().toString();
6880
s3Client.putObject(PutObjectRequest.builder()
6981
.bucket(bucketName)

0 commit comments

Comments
 (0)