1

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?

rajadilipkolli
  • 3,475
  • 2
  • 26
  • 49
Sanjeev Delhi
  • 11
  • 1
  • 2
  • Be aware of the maximum mutation size. And storing blobs larger than 1MB (IIRC) is not recommended. – xmas79 Oct 27 '16 at 04:12

1 Answers1

5

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.

Alec Collier
  • 1,483
  • 8
  • 9
  • Thanks Alec! I tried above link.I am working on Linux server which is at remote location. I am getting following error: – Sanjeev Delhi Oct 27 '16 at 10:13
  • Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed. – Sanjeev Delhi Oct 27 '16 at 10:59