Commit fb0a519a by Amparo Oliver

prueba Images path

parent 6b5090bc
......@@ -84,6 +84,28 @@ public class BirthdayController {
throw new RuntimeException(e);
}
if(!file.isEmpty()) {
String originalFilename = file.getOriginalFilename();
String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
// Verifica que el archivo sea jpg o png
if (fileExtension.equals("jpg") || fileExtension.equals("png")) {
Path directorioImagenes = Paths.get("uploadsBirthday/" + DigestUtils.md5Hex(originalFilename) + "." + fileExtension);
String rutaAbsoluta = directorioImagenes.toFile().getAbsolutePath();
try {
byte[] bytesImg = file.getBytes();
Path rutaCompleta = Paths.get(rutaAbsoluta);
Files.write(rutaCompleta, bytesImg);
// Si todo sale bien, guarda la foto en la base de datos
birthday.setFoto("http://192.168.16.90:8888/uploadsBirthday/" + DigestUtils.md5Hex(originalFilename) + "." + fileExtension);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
// Maneja el caso en que el formato del archivo no sea jpg o png
model.addAttribute("errorFormato", true);
return "birthday-form";
}
/*
Path directorioImagenes= Paths.get("images/"+ DigestUtils.md5Hex(file.getOriginalFilename()) + ".jpg");
String rutaAbsoluta = directorioImagenes.toFile().getAbsolutePath();
try {
......@@ -91,10 +113,12 @@ public class BirthdayController {
Path rutaCompleta=Paths.get(rutaAbsoluta);
Files.write(rutaCompleta, bytesImg);
// si todo salio bien guardamos la foto en la base de datos
birthday.setFoto("http://localhost:8080/images/"+ DigestUtils.md5Hex(file.getOriginalFilename()) + ".jpg");
birthday.setFoto("http://192.168.16.90:8888/images/"+ DigestUtils.md5Hex(file.getOriginalFilename()) + ".jpg");
} catch (IOException e) {
throw new RuntimeException(e);
}
*/
}
if(id != null ) birthday.setId(id);
birthdayRepository.save(birthday);
......
......@@ -7,7 +7,7 @@
<layout:put block="contents" type="REPLACE">
<div class="card justify-content-center mx-auto mt-2" style="width: 20rem;">
<div class="card-header">
<h5>Cumpleaño</h5>
<h5>Cumpleaños</h5>
</div>
<form:form
action="/cumples/${cumple.id == null ? 'agregar' : 'modificar/'.concat(cumple.id)}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment