use of de.tudarmstadt.ukp.clarin.webanno.export.ProjectExportRequest in project webanno by webanno.
the class RemoteApiController2 method projectExport.
@ApiOperation(value = "Export a project to a ZIP file")
@RequestMapping(value = ("/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + EXPORT), method = RequestMethod.GET, produces = { "application/zip", APPLICATION_JSON_UTF8_VALUE })
public ResponseEntity<InputStreamResource> projectExport(@PathVariable(PARAM_PROJECT_ID) long aProjectId) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
ProjectExportRequest per = new ProjectExportRequest(Model.of(project), "bin");
File exportedFile = exportService.generateZipFile(per);
// Turn the file into a resource and auto-delete the file when the resource closes the
// stream.
InputStreamResource result = new InputStreamResource(new FileInputStream(exportedFile) {
@Override
public void close() throws IOException {
super.close();
FileUtils.forceDelete(exportedFile);
}
});
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.valueOf("application/zip"));
httpHeaders.setContentLength(exportedFile.length());
httpHeaders.set("Content-Disposition", "attachment; filename=\"" + exportedFile.getName() + "\"");
return new ResponseEntity<>(result, httpHeaders, HttpStatus.OK);
}
Aggregations