From 8c26b56e91da826abec2fbb30e4088e4438253ae Mon Sep 17 00:00:00 2001 From: Henintsoa Date: Fri, 26 Nov 2021 01:31:42 +0300 Subject: [PATCH] Carto image file name --- .../aren/ws/rest/DocumentRESTFacade.java | 22 ++++++++++++++----- .../assets/js/views/createDebateSurCarte.vue | 2 +- .../js/views/documentDebatesSurCarte.vue | 3 +-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java b/src/main/java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java index 01e059d..fd68a48 100644 --- a/src/main/java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java +++ b/src/main/java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java @@ -7,6 +7,9 @@ import javax.inject.Inject; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Context; + +import javax.servlet.ServletContext; import fr.lirmm.aren.model.aaf.UploadedFile; import fr.lirmm.aren.service.DocumentService; @@ -29,6 +32,9 @@ public class DocumentRESTFacade extends AbstractRESTFacade { @Inject private DocumentService documentService; + @Context + private ServletContext servletContext; + /** * * @return @@ -102,18 +108,22 @@ public class DocumentRESTFacade extends AbstractRESTFacade { public Response uploadPdfFile(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception { - File UPLOAD_PATH = new File("/tmp/img/"); - if (! UPLOAD_PATH.exists()){ - UPLOAD_PATH.mkdir(); + String realPath = servletContext.getRealPath(""); + File uploadPath = new File(realPath + "/assets/carto"); + if (!uploadPath.exists()){ + uploadPath.mkdir(); } UploadedFile uploadedFile=new UploadedFile() ; try { + String fileName = "carto"+System.currentTimeMillis()+ fileMetaData.getFileName().substring(fileMetaData.getFileName().lastIndexOf(".")); + String uploadedCartoLocation = realPath + "/assets/carto/" + fileName; int read = 0; byte[] bytes = new byte[1024]; - String filename=UPLOAD_PATH +"carto"+System.currentTimeMillis()+ fileMetaData.getFileName().substring(fileMetaData.getFileName().lastIndexOf(".")) ; - File file=new File(filename) ; + + File file = new File(uploadedCartoLocation) ; OutputStream out = new FileOutputStream(file); + while ((read = fileInputStream.read(bytes)) != -1) { out.write(bytes, 0, read); @@ -121,7 +131,7 @@ public class DocumentRESTFacade extends AbstractRESTFacade { out.flush(); out.close(); - uploadedFile.setName(file.getAbsolutePath()); + uploadedFile.setName(file.getName()); } catch (IOException e) { throw new WebApplicationException("Error while uploading file. Please try again !!"); diff --git a/src/main/webapp/assets/js/views/createDebateSurCarte.vue b/src/main/webapp/assets/js/views/createDebateSurCarte.vue index a2bff25..d347633 100644 --- a/src/main/webapp/assets/js/views/createDebateSurCarte.vue +++ b/src/main/webapp/assets/js/views/createDebateSurCarte.vue @@ -262,7 +262,7 @@ validateLabel: this.$t('yes'), callback: (returnValue) => { if (returnValue) { - this.$router.push('/debates/' + this.debate.id); + this.$router.push('/debats-sur-cartes/' + this.debate.id); } else { this.reinit(); } diff --git a/src/main/webapp/assets/js/views/documentDebatesSurCarte.vue b/src/main/webapp/assets/js/views/documentDebatesSurCarte.vue index 4bb9095..439b6f1 100644 --- a/src/main/webapp/assets/js/views/documentDebatesSurCarte.vue +++ b/src/main/webapp/assets/js/views/documentDebatesSurCarte.vue @@ -189,8 +189,7 @@ module.exports = { ArenService.uploadMap({ data: this.selectedCarto, onSuccess: ({name}) => { - //console.log(name); - this.document.mapLink = name; + this.document.mapLink = "assets/carto/"+name; ArenService.Documents.createOrUpdate({ data: this.document, onSuccess: (document) => {