Search in sources :

Example 6 with AbstractPaperFile

use of com.odysseusinc.arachne.portal.model.AbstractPaperFile in project ArachneCentralAPI by OHDSI.

the class BasePaperController method downloadFile.

@ApiOperation("Download file of the Paper")
@RequestMapping(value = "/{id}/files/{fileUuid}/download", method = GET)
public void downloadFile(@PathVariable("id") Long id, @PathVariable("fileUuid") String uuid, @RequestParam("type") PaperFileType type, HttpServletResponse response) throws PermissionDeniedException, IOException {
    final AbstractPaperFile paperFile = paperService.getFile(id, uuid, type);
    final InputStream inputStream = fileService.getFileInputStream(paperFile);
    response.setContentType(paperFile.getContentType());
    response.setHeader("Content-Disposition", "attachment; filename=" + paperFile.getRealName());
    response.setHeader("Content-type", paperFile.getContentType());
    IOUtils.copy(inputStream, response.getOutputStream());
    response.flushBuffer();
}
Also used : InputStream(java.io.InputStream) AbstractPaperFile(com.odysseusinc.arachne.portal.model.AbstractPaperFile) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AbstractPaperFile (com.odysseusinc.arachne.portal.model.AbstractPaperFile)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Paper (com.odysseusinc.arachne.portal.model.Paper)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)1 PaperFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.PaperFileDTO)1 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 AntivirusJob (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob)1 AntivirusJobEvent (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent)1 AntivirusJobFileType (com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1