mirror of
https://github.com/ArenMg/aren.git
synced 2024-11-16 21:50:50 +00:00
Carto image file name
This commit is contained in:
parent
86613d0312
commit
8c26b56e91
3 changed files with 18 additions and 9 deletions
|
@ -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<Document> {
|
|||
@Inject
|
||||
private DocumentService documentService;
|
||||
|
||||
@Context
|
||||
private ServletContext servletContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
|
@ -102,18 +108,22 @@ public class DocumentRESTFacade extends AbstractRESTFacade<Document> {
|
|||
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<Document> {
|
|||
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 !!");
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue