php - Getting BLOB from mysql database to android -
i have mysql database following schema
(int id, int sys_id, blob data) there can multiple data same sys_id, i.e. (1,1, blobdata1), (2,1, blobdata2) etc. valid entries. blob data compressed audio. when rows particular sys_id combined valid compressed audio data produced.
i want send blob data android device. have tried following php code send data not received expected @ client side.
$conn = mysql_connect("localhost","root",""); mysql_select_db("mydb", $conn); global $blobid; $blobid = $_get['id']; $result = mysql_query("select data table sys_id=$blobid"); if( mysql_num_rows($result) == 0 ) die("no rows returned"); while($row = mysql_fetch_array($result) ) { // correct way of concatenating binary data $temp .= $row['data']; } // problem: should sent echo $temp; i don't mind if rows can received @ client end , can concatenated or operated upon locally there.
at client side, following:
// connect server public void connect(url url) { httpurlconnection urlconnection = null; try { urlconnection = (httpurlconnection)url.openconnection(); inputstream in = new bufferedinputstream(urlconnection.getinputstream()); result = readstream(in); //problem, how should parse resultant string decompress(result.getbytes()); // result.getbytes() returns null } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (exception e) { e.printstacktrace(); } } // reading incoming stream public static string readstream(inputstream in) throws ioexception { stringbuilder sb = new stringbuilder(); bufferedreader r = new bufferedreader(new inputstreamreader(in),1000); (string line = r.readline(); line != null; line =r.readline()){ sb.append(line); } in.close(); return sb.tostring(); } // definition decompression utility public short[] decompress(byte[] codbytes);
you can encode data want send in json format as
echo json_encode($response); and send json device , parse accordingly. parsing refer here
Comments
Post a Comment