use of org.icij.datashare.text.indexing.elasticsearch.SourceExtractor in project datashare by ICIJ.
the class DocumentResource method getPayload.
private Payload getPayload(Document doc, String index, boolean inline, boolean filterMetadata) throws IOException {
try (InputStream from = new SourceExtractor(filterMetadata).getSource(project(index), doc)) {
String contentType = ofNullable(doc.getContentType()).orElse(ContentTypes.get(doc.getPath().toFile().getName()));
Payload payload = new Payload(contentType, InputStreams.readBytes(from));
String fileName = doc.isRootDocument() ? doc.getName() : doc.getId().substring(0, 10) + "." + FileExtension.get(contentType);
return inline ? payload : payload.withHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
} catch (FileNotFoundException fnf) {
return Payload.notFound();
}
}
Aggregations