1

我希望将图像作为字节缓冲区插入到 cassandra 表中。

表是:员工(姓名文本,图像块)

我已经使用 Java 以字节缓冲区的形式将图像存储到变量 bb 中。如何将此字节缓冲区 bb 中的数据插入到 cassandra 表中?有人可以帮忙吗?

4

1 回答 1

5

您应该能够直接将 ByteBuffer 与 Java 驱动程序一起使用。

请参阅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));

看到他们直接将 ByteBuffer 绑定到准备好的语句中的 blob-type 参数。

于 2016-10-26T22:59:16.700 回答