Sanjeev Delhi
Sanjeev Delhi

Reputation: 21

Insert image into cassandra blob using Java

I wish to insert image as bytebuffer into cassandra table.

Table is: Employees(Name text,Image blob)

I had stored image into variable bb in form of bytebuffer using Java. How to insert data from this bytebuffer bb into cassandra table? Can anyone please help?

Upvotes: 2

Views: 5451

Answers (1)

Alec  Collier
Alec Collier

Reputation: 1523

You should be able to use the ByteBuffer directly with the Java driver.

See the example on http://ac31004.blogspot.com.au/2014/03/saving-image-in-cassandra-blob-field.html:

ByteBuffer buffer =ByteBuffer.wrap(b);

....
// image is of type blob
PreparedStatement ps = session.prepare("insert into Messages (image, user, interaction_time,imagelength) values(?,?,?,?)");
BoundStatement boundStatement = new BoundStatement(ps);

session.execute(boundStatement.bind(buffer, "Andy", convertor.getTimeUUID(),length));

See they directly bind the ByteBuffer to the blob-type parameter in the prepared statement.

Upvotes: 6

Related Questions