Carto image file name

This commit is contained in:
Henintsoa 2021-11-26 01:31:42 +03:00
parent 86613d0312
commit 8c26b56e91
3 changed files with 18 additions and 9 deletions

View file

@ -7,6 +7,9 @@ import javax.inject.Inject;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; 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.model.aaf.UploadedFile;
import fr.lirmm.aren.service.DocumentService; import fr.lirmm.aren.service.DocumentService;
@ -29,6 +32,9 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
@Inject @Inject
private DocumentService documentService; private DocumentService documentService;
@Context
private ServletContext servletContext;
/** /**
* *
* @return * @return
@ -102,18 +108,22 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
public Response uploadPdfFile(@FormDataParam("file") InputStream fileInputStream, public Response uploadPdfFile(@FormDataParam("file") InputStream fileInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception @FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception
{ {
File UPLOAD_PATH = new File("/tmp/img/"); String realPath = servletContext.getRealPath("");
if (! UPLOAD_PATH.exists()){ File uploadPath = new File(realPath + "/assets/carto");
UPLOAD_PATH.mkdir(); if (!uploadPath.exists()){
uploadPath.mkdir();
} }
UploadedFile uploadedFile=new UploadedFile() ; UploadedFile uploadedFile=new UploadedFile() ;
try try
{ {
String fileName = "carto"+System.currentTimeMillis()+ fileMetaData.getFileName().substring(fileMetaData.getFileName().lastIndexOf("."));
String uploadedCartoLocation = realPath + "/assets/carto/" + fileName;
int read = 0; int read = 0;
byte[] bytes = new byte[1024]; 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); OutputStream out = new FileOutputStream(file);
while ((read = fileInputStream.read(bytes)) != -1) while ((read = fileInputStream.read(bytes)) != -1)
{ {
out.write(bytes, 0, read); out.write(bytes, 0, read);
@ -121,7 +131,7 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
out.flush(); out.flush();
out.close(); out.close();
uploadedFile.setName(file.getAbsolutePath()); uploadedFile.setName(file.getName());
} catch (IOException e) } catch (IOException e)
{ {
throw new WebApplicationException("Error while uploading file. Please try again !!"); throw new WebApplicationException("Error while uploading file. Please try again !!");

View file

@ -262,7 +262,7 @@
validateLabel: this.$t('yes'), validateLabel: this.$t('yes'),
callback: (returnValue) => { callback: (returnValue) => {
if (returnValue) { if (returnValue) {
this.$router.push('/debates/' + this.debate.id); this.$router.push('/debats-sur-cartes/' + this.debate.id);
} else { } else {
this.reinit(); this.reinit();
} }

View file

@ -189,8 +189,7 @@ module.exports = {
ArenService.uploadMap({ ArenService.uploadMap({
data: this.selectedCarto, data: this.selectedCarto,
onSuccess: ({name}) => { onSuccess: ({name}) => {
//console.log(name); this.document.mapLink = "assets/carto/"+name;
this.document.mapLink = name;
ArenService.Documents.createOrUpdate({ ArenService.Documents.createOrUpdate({
data: this.document, data: this.document,
onSuccess: (document) => { onSuccess: (document) => {