How do I store and load byte array (or image) to/from Cassandra?

575 Views Asked by At

Is there a way to store byte array in to cql database? I tried with blob but it didn't work. The table still have the blob column but I can't load nor store it. Here the code to create table

CREATE TABLE tb (id int PRIMARY KEY, data blob);

The loading code

        public Image convertImgFromByte()
        {
            string query = "SELECT data FROM tb where id = " +id + " ALLOW FILTERING;";
            var results = DataConnection.Ins.session.Execute(query).FirstOrDefault();
            byte[] arr = results.GetValue<byte[]>("picture");
    
            using (var ms = new MemoryStream(arr))
            {
                Image img= Image.FromStream(ms);
                return img;
            }
            return null;
        }

Can anyones give me some suggestion?

1

There are 1 best solutions below

1
Imran On

There are two possibilities

Can you directly access the SQL in CLI and ensure the image exists. or The tag you are referring "picture" could be different as in the byte array you can also lookup with index.