File tree 3 files changed +26
-0
lines changed
src/main/java/com/example/bucket 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 42
42
<artifactId >aws-java-sdk</artifactId >
43
43
<version >1.11.133</version >
44
44
</dependency >
45
+
46
+ <dependency >
47
+ <groupId >commons-io</groupId >
48
+ <artifactId >commons-io</artifactId >
49
+ <version >2.4</version >
50
+ </dependency >
45
51
</dependencies >
46
52
47
53
<build >
Original file line number Diff line number Diff line change @@ -33,4 +33,9 @@ public String uploadFile(@RequestPart(value = "file") MultipartFile file) {
33
33
public String deleteFile (@ RequestPart (value = "url" ) String fileUrl ) {
34
34
return this .amazonClient .deleteFileFromS3Bucket (fileUrl );
35
35
}
36
+
37
+ @ GetMapping ("/downloadFiles" )
38
+ public void downloadFiles () {
39
+ this .amazonClient .downloadAllS3Object ();
40
+ }
36
41
}
Original file line number Diff line number Diff line change 5
5
import com .amazonaws .services .s3 .AmazonS3 ;
6
6
import com .amazonaws .services .s3 .AmazonS3Client ;
7
7
import com .amazonaws .services .s3 .model .*;
8
+ import org .apache .commons .io .FileUtils ;
8
9
import org .springframework .beans .factory .annotation .Value ;
9
10
import org .springframework .stereotype .Service ;
10
11
import org .springframework .web .multipart .MultipartFile ;
@@ -80,4 +81,18 @@ public List<S3ObjectSummary> listFilesTos3bucket() {
80
81
81
82
return s3ObjectSummaries ;
82
83
}
84
+
85
+ public void downloadAllS3Object () {
86
+ try {
87
+ List <S3ObjectSummary > s3ObjectSummaries = listFilesTos3bucket ();
88
+ for (S3ObjectSummary s3ObjectSummary : s3ObjectSummaries ) {
89
+ S3Object object = s3client .getObject (s3ObjectSummary .getBucketName (),
90
+ s3ObjectSummary .getKey ());
91
+ File file = new File (s3ObjectSummary .getKey ());
92
+ FileUtils .copyInputStreamToFile (object .getObjectContent (), file );
93
+ }
94
+ } catch (IOException e ) {
95
+ e .printStackTrace ();
96
+ }
97
+ }
83
98
}
You can’t perform that action at this time.
0 commit comments