Hi
I am trying to build a app services which will handle mp3 audio file store in database in BLOB field and also retrieve from db,I could not able to retrieve blob data.
its show [message] => Resource id #254 and also in json format like
{
“message”: “Serialization of View data failed.”,
“url”: “/blerb/api/chats/sent”,
}
Hey Kamal,
I was struggling with the same Problem. Long Story Short: PDO(The underlying native PHP Framework) gives back blob/bytea fields as a resource. So what do you do? The trick is to access the data via a stream and then base64_encode it. Just add this to your table class:
public function beforeFind(Event $event, Query $query, ArrayObject $options){
$query->formatResults(function($results){
return $results->map(function($row){
if(isset($row['picture'])){
$row['mp3'] = "data:audio/mpeg;base64,".base64_encode(stream_get_contents($row['mp3']));
}
return $row;
});
});
}
This should work. Of course you have to name the fields to fit your namings.