Apache OAK Direct Binary Access with S3DataStore

88 views Asked by At

I'm trying to figure out how the direct binary access feature works with Apache Oak.

My understanding so far is, I can set binary properties to nodes, and later, I should be able to get a direct download link (from S3).

First, I created a node and added a binary property with the contents of some file.

val ntFile = session.getRootNode.addNode(path, "nt:file")
val ntResource = ntFile.addNode("jcr:content", "nt:resource")

ntResource.setProperty("jcr:mimeType", "application/octet-stream")
ntResource.setProperty("jcr:lastModified", Calendar.getInstance())

val fStream = new FileInputStream("/home/evren/cast.webm")
val bin = session.getValueFactory.asInstanceOf[JackrabbitValueFactory].createBinary(fStream)
ntResource.setProperty("jcr:data", bin)

And I can see on the AWS Console, my binary is uploaded.

But, still, I cannot generate direct download URI, even following the documentation on the OAK website. (So the code continues)

session.save()
session.refresh(false)

val binary = session.getRootNode.getNode(path)
  .getNode("jcr:content").getProperty("jcr:data").getValue.getBinary

val uri = binary.asInstanceOf[BinaryDownload].getURI(BinaryDownloadOptions.DEFAULT)

It's always returning null.

Someone please could point me to what I am doing wrong or is my understanding.

Thanks in advance.

1

There are 1 answers

0
Evren Yortucboylu On

I figured it out. In case, anyone else is facing the same issue, the trick is to register your BlobStore using a WhiteBoard.

This explains a lot about the issue that, I could upload files directly using BlobStorage but OAK itself could not use the BlobStore functionality to get a direct download link.

val wb = new DefaultWhiteboard()

// register s3/azure as BlobAccessProvider
wb.register(
   classOf[BlobAccessProvider],
   blobStore.asInstanceOf[BlobAccessProvider],
   Collections.emptyMap()
)

val jcrRepo = new Jcr(nodeStore).`with`(wb).createRepository()

And once you create your JCR Repo like this, direct binary download/upload works as expected.