Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rubén Ramírez
/
MangAffinity
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
06a8ae78
authored
Mar 06, 2025
by
Rubén Ramírez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat: [Imagenes]: Añadidos archivos para que los recursos tengan fotos
parent
4e4d73a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
src/main/java/com/ujaen/tfg/mangaffinity/config/WebConfig.java
src/main/java/com/ujaen/tfg/mangaffinity/rest/UploadController.java
uploads/Arduino_Logo.svg_.png
src/main/java/com/ujaen/tfg/mangaffinity/config/WebConfig.java
0 → 100644
View file @
06a8ae78
package
com
.
ujaen
.
tfg
.
mangaffinity
.
config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
@Configuration
public
class
WebConfig
implements
WebMvcConfigurer
{
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
// Usar una ruta relativa para servir archivos estáticos desde la carpeta uploads
registry
.
addResourceHandler
(
"/uploads/**"
)
.
addResourceLocations
(
"file:./uploads/"
);
}
}
src/main/java/com/ujaen/tfg/mangaffinity/rest/UploadController.java
0 → 100644
View file @
06a8ae78
package
com
.
ujaen
.
tfg
.
mangaffinity
.
rest
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.UrlResource
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.net.MalformedURLException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
@RestController
@RequestMapping
(
"/uploads"
)
public
class
UploadController
{
private
final
Path
uploadDir
=
Paths
.
get
(
"uploads"
);
@GetMapping
(
"/{filename:.+}"
)
public
ResponseEntity
<
Resource
>
getFile
(
@PathVariable
String
filename
)
{
try
{
Path
file
=
uploadDir
.
resolve
(
filename
);
Resource
resource
=
new
UrlResource
(
file
.
toUri
());
if
(
resource
.
exists
()
||
resource
.
isReadable
())
{
String
contentType
=
"application/octet-stream"
;
if
(
filename
.
endsWith
(
".png"
))
contentType
=
"image/png"
;
else
if
(
filename
.
endsWith
(
".jpg"
)
||
filename
.
endsWith
(
".jpeg"
))
contentType
=
"image/jpeg"
;
return
ResponseEntity
.
ok
()
.
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"inline; filename=\""
+
resource
.
getFilename
()
+
"\""
)
.
header
(
HttpHeaders
.
CONTENT_TYPE
,
contentType
)
.
body
(
resource
);
}
else
{
return
ResponseEntity
.
notFound
().
build
();
}
}
catch
(
MalformedURLException
e
)
{
return
ResponseEntity
.
badRequest
().
build
();
}
}
}
uploads/Arduino_Logo.svg_.png
0 → 100644
View file @
06a8ae78
52.2 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment