我们是如何使用node js将图像插入cassandra数据库的,我在下面尝试过。
我已经使用base64(image)来存储映像,但是我需要将base64存储在cassandra的blob数据类型中。我知道cassandra中的blob数据类型相当于node js中的buffer数据类型。
var cassandra=require('cassandra-driver');
var client=new cassandra.Client({contactPoints:['localhost'],localDataCenter:"datacenter1",keyspace:"employee"});
var path=require('path');
var fs=require('fs');
var base64 = fs.readFileSync(path.resolve(__dirname + '/download.jpeg'), 'base64');
var imageBuffer = new Buffer(base64, 'base64');
var query="INSERT INTO photo(id,image) VALUES ('ranjith',imageBuffer)";
client.execute(query,function(err){
if(err) {
console.log(err);
} else {
console.log('success');
}
});
以下是错误消息:
> { ResponseError: line 1:57 no viable alternative at input ')'
> (...id,image) VALUES ('ranjith',[imageBuffer]))
> at FrameReader.readError (/home/innvoot/Desktop/cassandra_and_node_trails/node_modules/cassandra-driver/lib/readers.js:326:15)
> at Parser.parseBody (/home/innvoot/Desktop/cassandra_and_node_trails/node_modules/cassandra-driver/lib/streams.js:194:66)
> at Parser._transform (/home/innvoot/Desktop/cassandra_and_node_trails/node_modules/cassandra-driver/lib/streams.js:137:10)
> at Parser.Transform._read (_stream_transform.js:186:10)
> at Parser.Transform._write (_stream_transform.js:174:12)
> at doWrite (_stream_writable.js:396:12)
> at writeOrBuffer (_stream_writable.js:382:5)
> at Parser.Writable.write (_stream_writable.js:290:11)
> at Protocol.ondata (_stream_readable.js:639:20)
> at emitOne (events.js:116:13) name: 'ResponseError', info: 'Represents an error message from the server', message: 'line 1:57
> no viable alternative at input \')\' (...id,image) VALUES
> (\'ranjith\',[imageBuffer]))', code: 8192, coordinator:
> '127.0.0.1:9042', query: 'INSERT INTO photo(id,image) VALUES
> (\'ranjith\',imageBuffer)' }
我期望得到“成功”的结果。
1条答案
按热度按时间k2arahey1#
我不是javascriptMaven,但看到了你的错误;
输入')'(…id,image)值('ranjith',[imagebuffer])处没有可行的替代方法
我觉得查询语法可能有问题,可以试试