hbase - 如何从 HBase 获取图像

标签 hbase hdfs

我的 HDFS 中有大约 1 G 的图像 .png 文件。任何人都可以建议我一种将索引值存储到 HBase 中的这些图像并通过查询 HBase 检索图像的方法。或者我如何使用 HDFS/HBase 来提供图像。请回复。

紧急需求:(

提前致谢

最佳答案

下面的代码会有所帮助。

    //to store image file to hbase  
    Configuration conf = HBaseConfiguration.create();
    HTable table = new HTable(conf, "test".getBytes());
    Put put = new Put("row1".getBytes());
    put.add("C".getBytes(), "image".getBytes(),
            extractBytes("/path/to/image/input.jpg"));
    table.put(put);

    //to retrieve the image
    Get get = new Get("row1".getBytes());

    Result result = table.get(get);
    byte[] arr = result.getValue("C".getBytes(), "image".getBytes());


    OutputStream out = new BufferedOutputStream(new FileOutputStream(
            "/path/to/image/output.jpg"));
    out.write(arr);

    //function to convert image file to bytes.
    public static byte[] extractBytes(String ImageName) throws IOException {

    File file = new File(ImageName);
    BufferedImage originalImage = ImageIO.read(file);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(originalImage, "jpg", baos);
    byte[] imageInByte = baos.toByteArray();
    return imageInByte;
}

关于hbase - 如何从 HBase 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7337786/

相关文章:

hadoop - 如何连接Hbase和Mysql

hadoop - Hbase 自动递增任何列/行键

hbase - 异步数据库教程?

hadoop - 复制文件 : Could only be replicated to 0 nodes, 而不是 1 时出现 HDFS 错误

hadoop - 致命的 master.HMaster : Unexpected state : . 。无法将其转移到 OFFLINE

database-design - Hadoop Hbase : Spreading column families across tables or not

linux - 无法列出 HDFS 目录中的文件,尽管我对目录具有读取权限

python - 在 hadoop 中加载大的日本文件

hadoop - HUE中的Filebrowser无法正常工作,用户上传失败

hadoop - 如何从Cloudera到Hortonworks进行distcp