add dependencies and start developing app
This commit is contained in:
37
pom.xml
37
pom.xml
@ -16,8 +16,8 @@
|
|||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.release>23</maven.compiler.release>
|
<maven.compiler.release>21</maven.compiler.release>
|
||||||
<java.version>23</java.version>
|
<java.version>21</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|
||||||
<s3.version>2.31.47</s3.version>
|
<s3.version>2.31.47</s3.version>
|
||||||
@ -27,24 +27,27 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>software.amazon.awssdk</groupId>
|
<groupId>software.amazon.awssdk</groupId>
|
||||||
<artifactId>s3</artifactId>
|
<artifactId>s3</artifactId>
|
||||||
|
<version>${s3.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jetty</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>software.amazon.awssdk</groupId>
|
|
||||||
<artifactId>s3</artifactId>
|
|
||||||
<version>${s3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
package ua.com.dxrkness;
|
package ua.com.dxrkness;
|
||||||
|
|
||||||
import software.amazon.awssdk.regions.Region;
|
import org.springframework.boot.SpringApplication;
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Main.class, args);
|
||||||
final var s3 = S3Client.builder()
|
|
||||||
.region(Region.EU_CENTRAL_1)
|
|
||||||
.build();
|
|
||||||
try (s3) {
|
|
||||||
s3.listBuckets().buckets().forEach(System.out::println);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,41 +0,0 @@
|
|||||||
package ua.com.dxrkness;
|
|
||||||
|
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
|
||||||
import software.amazon.awssdk.services.s3.model.S3Object;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class S3Service {
|
|
||||||
private final S3Client client;
|
|
||||||
private final String bucketName;
|
|
||||||
|
|
||||||
public S3Service(S3Client client, String bucketName) {
|
|
||||||
this.client = client;
|
|
||||||
this.bucketName = bucketName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createDirectory(Path path) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean delete(Path path) {
|
|
||||||
return client
|
|
||||||
.deleteObject(b -> b.bucket(bucketName).key(path.toString()).build())
|
|
||||||
.deleteMarker();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<S3Object> listing(Path path) {
|
|
||||||
return client
|
|
||||||
.listObjectsV2(b -> b.bucket(bucketName).build())
|
|
||||||
.contents();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void uploadFile(Path path) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String downloadFile(Path path) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
16
src/main/java/ua/com/dxrkness/config/S3Configuration.java
Normal file
16
src/main/java/ua/com/dxrkness/config/S3Configuration.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package ua.com.dxrkness.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import software.amazon.awssdk.regions.Region;
|
||||||
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class S3Configuration {
|
||||||
|
@Bean
|
||||||
|
public S3Client client() {
|
||||||
|
return S3Client.builder()
|
||||||
|
.region(Region.EU_CENTRAL_1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package ua.com.dxrkness.controller;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.function.RouterFunction;
|
||||||
|
import org.springframework.web.servlet.function.RouterFunctions;
|
||||||
|
import org.springframework.web.servlet.function.ServerResponse;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class S3ControllerConfig {
|
||||||
|
@Bean
|
||||||
|
public RouterFunction<ServerResponse> router() {
|
||||||
|
return RouterFunctions.route()
|
||||||
|
.GET()
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package ua.com.dxrkness.controller;
|
||||||
|
|
||||||
|
public class S3FileHandler {
|
||||||
|
}
|
59
src/main/java/ua/com/dxrkness/service/S3Service.java
Normal file
59
src/main/java/ua/com/dxrkness/service/S3Service.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package ua.com.dxrkness.service;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import software.amazon.awssdk.core.sync.RequestBody;
|
||||||
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
|
import software.amazon.awssdk.services.s3.model.S3Object;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.channels.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class S3Service {
|
||||||
|
private final S3Client client;
|
||||||
|
private final String bucketName;
|
||||||
|
|
||||||
|
public S3Service(S3Client client,
|
||||||
|
@Value("s3.bucket-name") String bucketName) {
|
||||||
|
this.client = client;
|
||||||
|
this.bucketName = bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createDirectory(Path path) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean delete(Path path) {
|
||||||
|
return client
|
||||||
|
.deleteObject(b -> b.bucket(bucketName).key(path.toString()).build())
|
||||||
|
.deleteMarker();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<S3Object> listing(Path path) {
|
||||||
|
return client
|
||||||
|
.listObjectsV2(b -> b.bucket(bucketName).build())
|
||||||
|
.contents();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean uploadFile(MultipartFile file) throws IOException {
|
||||||
|
return client
|
||||||
|
.putObject(b -> b
|
||||||
|
.bucket(bucketName)
|
||||||
|
.key(file.getName()),
|
||||||
|
RequestBody.fromInputStream(file.getInputStream(), file.getSize()))
|
||||||
|
.bucketKeyEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reader downloadFile(String key, Path destinationPath) {
|
||||||
|
return Channels.newReader(
|
||||||
|
Channels.newChannel(client
|
||||||
|
.getObject(b -> b.bucket(bucketName).key(key))),
|
||||||
|
StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
1
src/main/resources/application.properties
Normal file
1
src/main/resources/application.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
s3.bucket-name=student-test-bucket-orlovos-2025
|
Reference in New Issue
Block a user