fix: fix minor bugs and change config to ec2 instance

This commit is contained in:
2025-05-26 00:00:09 +03:00
parent 18571e0e0e
commit 82b9c12773
4 changed files with 16 additions and 3 deletions

View File

@ -64,7 +64,7 @@ public class S3FileHandler {
.created(URI.create("/files"))
.body(new DirectoryPath(
path.resolve(
file.getSubmittedFileName()
file.getSubmittedFileName().replaceAll("\s", "_")
)
));
} catch (IOException e) {

View File

@ -3,6 +3,7 @@ package ua.com.dxrkness.controller;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
@ -35,4 +36,10 @@ public class S3FileHandlerConfig implements WebMvcConfigurer {
.allowedHeaders("*")
.allowedOriginPatterns("*");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/public/**")
.addResourceLocations("classpath:/static/");
}
}

View File

@ -102,7 +102,7 @@ public class S3Service {
client.putObject(b -> b
.bucket(bucketName)
.key(destinationPath
.resolve(file.getSubmittedFileName())
.resolve(file.getSubmittedFileName().replace("\s", "_"))
.toString()),
RequestBody.fromInputStream(file.getInputStream(), file.getSize()));
}

View File

@ -34,8 +34,14 @@
<button onclick="navigateToPath()">Go to Path</button>
</div>
<div>
<h3>Just a meme from S3 bucket</h3>
<img width="40%"
src="https://student-test-bucket-orlovos-2025.s3.eu-central-1.amazonaws.com/meme.jpg">
</div>
<script>
const baseUrl = 'http://localhost:8080';
const baseUrl = 'http://18.199.97.136:8080';
let currentPath = '';
document.addEventListener('DOMContentLoaded', function() {