try {
ODocument doc=AssetService.getByName(name);
if (doc==null || doc.field("file")==null) return notFound();
ORecordBytes record = doc.field("file");
ByteArrayOutputStream out = new ByteArrayOutputStream();
record.toOutputStream(out);
response().setContentType(AssetService.getContentType(doc));
if(forceDownload) response().setHeader("Content-Disposition", "attachment; filename=\""+URLEncoder.encode((String)doc.field("fileName"),"UTF-8")+"\"");
response().setHeader("Content-Length", ((Long)doc.field("contentLength")).toString());
//return ok(new ByteArrayInputStream(out.toByteArray()));
return ok(out.toByteArray());