Image error solve update

This commit is contained in:
2025-10-10 09:48:04 +05:30
parent 2f6c0a08b4
commit 7763940b2a
3 changed files with 36 additions and 6 deletions

View File

@ -0,0 +1,29 @@
package net.shyshkin.study.fullstack.supportportal.backend.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.io.File;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Value("${file.upload.directory}")
private String uploadDirectory;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Make sure the path ends with a separator
String uploadPath = uploadDirectory;
if (!uploadPath.endsWith(File.separator)) {
uploadPath += File.separator;
}
// Serve uploaded files publicly at /uploads/**
registry.addResourceHandler("/uploads/**")
.addResourceLocations("file:" + uploadPath)
.setCachePeriod(3600); // Cache for 1 hour
}
}

View File

@ -41,7 +41,7 @@ spring:
throw-exception-if-no-handler-found: true
web:
resources:
add-mappings: false
add-mappings: true # Changed from false to true to serve static files
# File upload configuration
file:
@ -50,10 +50,10 @@ file:
app:
base-url: ${APP_BASE_URL:http://localhost:8080}
# Updated public URLs to include image endpoints
public-urls: /user/login,/user/register,/user/*/profile-image,/user/*/profile-image/**,/professors,/professors/**,/api/posts,/api/posts/*,/api/posts/posted,/api/posts/tag/*,/api/posts/tags/count,/api/files/**,/professor,/professor/*,/api/events,/api/events/*,/api/public/**,/api/jobs/active,/api/job-applications,/api/courses/active,/api/courses/*,/api/course-applications,/api/upcoming-events/active
# Added /uploads/** to public URLs
public-urls: /user/login,/user/register,/user/*/profile-image,/user/*/profile-image/**,/professors,/professors/**,/api/posts,/api/posts/*,/api/posts/posted,/api/posts/tag/*,/api/posts/tags/count,/api/files/**,/uploads/**,/professor,/professor/*,/api/events,/api/events/*,/api/public/**,/api/jobs/active,/api/job-applications,/api/courses/active,/api/courses/*,/api/course-applications,/api/upcoming-events/active
cors:
allowed-origins: http://localhost:4200,https://localhost:4200,http://localhost:3000,https://localhost:3000,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://portal.shyshkin.net,*
allowed-origins: http://localhost:4200,https://localhost:4200,http://localhost:3000,https://localhost:3000,http://art-support-portal.s3-website.eu-north-1.amazonaws.com,http://portal.shyshkin.net,https://maincmc.rootxwire.com,https://cmcbackend.rootxwire.com
jwt:
secret: custom_text
@ -67,9 +67,9 @@ file:
upload:
directory: /var/uploads/blog-images
app:
base-url: https://cmcadminfrontend.com
base-url: https://cmcbackend.rootxwire.com
cors:
allowed-origins: https://cmcadminfrontend.com,https://cmcadminfrontend.com
allowed-origins: https://maincmc.rootxwire.com,https://cmcbackend.rootxwire.com, https://cmcadminfrontend.rootxwire.com
---
# Development file upload configuration with custom directory

View File

@ -1,3 +1,4 @@
<app-menu></app-menu>
<div class="container mt-4">
<!-- Header -->
<div class="row mb-3">