3

I've read many posts regarding PHP/JSON blob processing, but, none seem to provide a clear cut example on how to proceed. I am trying to communicate with an SQL database on a server. The table in question has a medium blob field. I use PHP and JSON to grab the data and display it on an Android phone. I have no problem with the non-blob data. I can grab it and display it with no problems. However, the blob data always returns as "null" via JSON. I understand that JSON does not directly support binary data, but, my question still remains, how do I access the blob data from the Android system? The blob data in question is mostly text files (ie. .PDF, .DOC, etc.). I have no control over the SQL table. More importantly, how do I get the blob field packaged with the rest of the data so I can process it on the Android platform? Any help would be greatly appreciated.

2
  • possible duplicate stackoverflow.com/questions/4855447/… Commented Feb 6, 2012 at 18:29
  • Hey - For some scenarios base64 encoding of binary data solves many problems. It will have a size of 3/2 the original data on the wire which is a problem, but all data is alphanums, why it is easy to transfer. It causes overhead both server and client side though and I dunno about php support, but perhaps? Commented Feb 6, 2012 at 18:31

1 Answer 1

1

Storing the binary data in a database table might be a bad idea, see this question: Storing Images in DB - Yea or Nay?

You can use base64_encode() in PHP to encode the binary data.

In PHP it might look something like this:

$row = mysql_fetch_assoc($res);
foreach($row as $key => $value){
    $json[$key] = base64_encode($value);
}
echo json_encode($json);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.