Scala - phantom - Saving blob to Cassandra

681 views Asked by At

I'm looking to save a file to cassandra

I'm using Scala with websudos" % "phantom-dsl_2.10" % "1.4.0" driver

I think I've got my model created with

sealed class CassandraRepoBlob extends CassandraTable[CassandraRepoBlob, CassandraBlob] {
  object id extends UUIDColumn(this) with PrimaryKey[UUID]

  object blobby extends BlobColumn(this)

and this seems to expect a case class of

case class CassandraBlob(
                        blobby: java.nio.ByteBuffer

I haven't been able to find many examples; so just want to check if I'm on the right track?

From here I guess I need to read my File to a ByteBuffer and I should be good to go?

Thanks

1

There are 1 answers

0
Rdesmond On BEST ANSWER

"From here I guess I need to read my File to a ByteBuffer and I should be good to go?" Yes, When I used java to write rows with a column of type blob being file contents, I had to convert the file contents to a ByteBuffer (really easy actually, ByteBuffer.wrap(Files.readAllBytes(file.toPath())) in java).