【问题标题】:How do I store and load byte array (or image) to/from Cassandra?如何在 Cassandra 中存储和加载字节数组(或图像)?
【发布时间】:2022-06-11 12:04:34
【问题描述】:

有没有办法将字节数组存储到 cql 数据库中?我尝试使用 blob,但它没有用。该表仍有 blob 列,但我无法加载或存储它。这里是创建表的代码

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

加载代码

        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;
        }

谁能给我一些建议?

【问题讨论】:

    标签: cassandra datastax-csharp-driver


    【解决方案1】:

    有两种可能,

    能否在 CLI 中直接访问 SQL 并确保映像存在。 或者 您所指的“图片”标签可能与字节数组中的不同,您也可以使用索引查找。

    【讨论】:

      猜你喜欢
      • 2011-05-28
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 2018-12-31
      • 2013-03-25
      • 1970-01-01
      相关资源
      最近更新 更多