简体   繁体   中英

Upload,retrive and display image in HBase using Thrift and Php

I have set up HBase and trying to use Thrift-Php to upload an image and then display it. I have one table with one column family named info and used something like:

$tmpName=$_FILES["file"]["tmp_name"];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
try {
    $mutations = array(
         new Mutation( array(
            'column' => 'info:pic',
            'value' => $data
            ) ),
            );
$client->mutateRow( $t, $username, $mutations );
   } catch ( IOError $e ) {
        echo( "expected error: {$e->message}\n" );
   }

Which seems to work as it stores something in Hbase and then

$arr = $client->getRow($t, $username);
foreach ( $arr as $k=>$TRowResult  ) {
$values = $TRowResult->columns;
asort( $values );
foreach ( $values as $k=>$v ) {
        $usr= $v->value;
        $content=$_GET['username'];
    header('Content-type: image/jpg');
        echo $usr;
}

}

But I get an error message saying that the image contains errors. Can someone provide an example in Php? Thank you.

I think, your problem is that you use $data = addslashes($data); when you store data. There's no need to quote characters when storing them to HBase.

And, you can retrieve data like this:

$values = $TRowResult->columns;
$usr= $values['info:pic']->value;
$content=$_GET['username'];
header('Content-type: image/jpg');
echo $usr;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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