-1
저는 Ruby on Rails를 사용하고 있으며 이미지를 직접 cassandra 데이터베이스에 저장하려고합니다.cassandra cql을 사용하여 이진 데이터를 저장하는 방법
cassandra-cql 보석이있는 파일을 어떻게 cassandra 데이터베이스에 저장할 수 있습니까? 그리고이 파일을 image_tag에 어떻게 표시 할 수 있습니까?
저는 Ruby on Rails를 사용하고 있으며 이미지를 직접 cassandra 데이터베이스에 저장하려고합니다.cassandra cql을 사용하여 이진 데이터를 저장하는 방법
cassandra-cql 보석이있는 파일을 어떻게 cassandra 데이터베이스에 저장할 수 있습니까? 그리고이 파일을 image_tag에 어떻게 표시 할 수 있습니까?
먼저 열의 유효성 검사기가 BytesType인지 확인하십시오. 그런 다음과 같이 카산드라으로 IMG를 삽입 할 수 :
File.open('/tmp/image.jpg', 'r') do |f|
img = f.read.force_encoding('ASCII-8BIT') # ensure cassandra-cql knows this is binary
handle.execute("insert into img (KEY, colA) values ('rowA', ?)", img);
end
을 다시 그것을 밖으로 가져 :
img = handle.execute("select colA from img where KEY = 'rowA'").fetch[0]
당신은 IMG를 스트리밍 할 수있는 조치 컨트롤러를 확인해야합니다 레일에서이 서비스를 제공하기 위해 disposition => 'inline'
와 send_data
를 사용하여 :
class ImgController < ApplicationController
def img
row_key = params['row_key']
col_name = params['col_name']
img = handle.execute("select ? from img where KEY = ?", col_name, row_key).fetch[0]
send_data(img, :filename => 'img.jpg', :type => 'image/jpeg', :disposition => 'inline')
end
end
이 그럼 당신은 IMAGE_TAG를 사용하면 해당 컨트롤러에 연결합니다. this question for more info on streaming images from a controller을보십시오.