patch prod
This commit is contained in:
@@ -39,6 +39,7 @@ import java.util.Optional;
|
||||
@Primary
|
||||
public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
|
||||
private static final String UPLOAD_DIR = "src/main/resources/static/images/articles";
|
||||
private static final Logger logger = LoggerFactory.getLogger(ArticleRepositoryImpl.class);
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private NamedParameterJdbcTemplate namedJdbcTemplate;
|
||||
@@ -341,7 +342,23 @@ public class ArticleRepositoryImpl implements ArticleRepository {
|
||||
}
|
||||
//Enregistrement du fichier
|
||||
MultipartFile file = article.getPhoto();
|
||||
|
||||
if (file != null && !file.isEmpty()) {
|
||||
try {
|
||||
// Renommer le fichier avec l'ID de l'article
|
||||
String newFileName = article.getId() + ".jpg";
|
||||
// Chemin du dossier de destination
|
||||
Path uploadPath = Paths.get(UPLOAD_DIR);
|
||||
// Créer le dossier s'il n'existe pas
|
||||
Files.createDirectories(uploadPath);
|
||||
// Chemin complet du fichier de destination
|
||||
Path filePath = uploadPath.resolve(newFileName);
|
||||
// Copier le fichier dans le dossier de destination
|
||||
FileCopyUtils.copy(file.getInputStream(), Files.newOutputStream(filePath));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// Gérer l'erreur
|
||||
}
|
||||
}
|
||||
}else {
|
||||
//Mettre à jour l'article
|
||||
|
||||
|
||||
Reference in New Issue
Block a user