File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 22
33import com .fasterxml .jackson .databind .ObjectMapper ;
44import lombok .SneakyThrows ;
5+ import net .coobird .thumbnailator .Thumbnails ;
56import org .springframework .beans .factory .annotation .Value ;
67import org .springframework .stereotype .Service ;
78import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
1415import software .amazon .awssdk .services .s3 .model .*;
1516
1617import java .io .ByteArrayInputStream ;
18+ import java .io .ByteArrayOutputStream ;
19+ import java .io .InputStream ;
1720import java .net .URI ;
1821import java .util .Base64 ;
1922import 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 )
You can’t perform that action at this time.
0 commit comments