From 4a0438bb6c878499850e565e27cc5b288fb83cc2 Mon Sep 17 00:00:00 2001 From: Arimihanta Date: Fri, 26 Nov 2021 08:23:35 +0300 Subject: [PATCH] modifier emplacement carte --- .../java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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..8eb3b79 100644 --- a/src/main/java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java +++ b/src/main/java/fr/lirmm/aren/ws/rest/DocumentRESTFacade.java @@ -15,6 +15,7 @@ import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataParam; import java.io.*; +import java.net.URLDecoder; import java.util.Set; /** @@ -102,7 +103,10 @@ 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/"); + String path=this.getClass().getClassLoader().getResource("").getPath() ; + String fullPath= URLDecoder.decode(path,"UTF-8") ; + System.out.println(fullPath.replace("WEB-INF/classes/","assets/img/carto")); + File UPLOAD_PATH = new File(fullPath.replace("WEB-INF/classes/","assets/img/carto")); if (! UPLOAD_PATH.exists()){ UPLOAD_PATH.mkdir(); } @@ -111,7 +115,7 @@ public class DocumentRESTFacade extends AbstractRESTFacade { { int read = 0; byte[] bytes = new byte[1024]; - String filename=UPLOAD_PATH +"carto"+System.currentTimeMillis()+ fileMetaData.getFileName().substring(fileMetaData.getFileName().lastIndexOf(".")) ; + String filename=UPLOAD_PATH +"//carto"+System.currentTimeMillis()+ fileMetaData.getFileName().substring(fileMetaData.getFileName().lastIndexOf(".")) ; File file=new File(filename) ; OutputStream out = new FileOutputStream(file); while ((read = fileInputStream.read(bytes)) != -1) @@ -121,7 +125,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 !!");