简体   繁体   English

Cassandra 2 - CQLEngine:存储图像错误

[英]Cassandra 2 - CQLEngine : Store Images error

I'm trying to store images in database.This is my code for get an Image : 我正在尝试将图像存储在数据库中。这是我获取图像的代码:

image = Image.open(...a resource on web...)
imageData = StringIO.StringIO()
image.save(imageData, image.format)
myImage = imageData.getvalue()

But when trying to store in database by this: 但是当试图通过这个存储在数据库中时:

myTable.create(...some fields , image=myImage)

I catch an exception with this message: 我收到此消息的异常:

Bad Request: Invalid STRING constant(ffd8ffe0.. and so on...adss4das) for image of type blob

I previously store images by these codes using Cassandra1.2.9! 我之前使用Cassandra1.2.9通过这些代码存储图像!

But when I installed Cassandra2.0 , this problem happened! 但是当我安装Cassandra2.0时,就出现了这个问题!

I check my code line by line,and I'm sure that error in the way of storing images in C2.0 or getting image. 我逐行检查我的代码,我确定在C2.0中存储图像或获取图像的方式存在错误。

I think you're having problems with this: https://github.com/datastax/python-driver/pull/39 . 我认为你遇到了这个问题: https//github.com/datastax/python-driver/pull/39 I'm sure that cqlengine isn't updated yet to take advantage of that fix (I just merged the pull request today), but that at least explains what the problem is. 我确定cqlengine尚未更新以利用该修复(我今天刚刚合并了拉取请求),但这至少解释了问题所在。

As a workaround, you might be able to do something like: 作为一种解决方法,您可以执行以下操作:

from binascii import hexlify

hex_image = '0x' + hexlify(myImage)
myTable.create(..., image=hex_image)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM