Returning a blob with json

后端 未结 3 709
温柔的废话
温柔的废话 2020-12-06 05:22

I\'m trying to create a rest service for my android application where an external database returns items to be stored in the applications local database. I\'ve got everythi

3条回答
  •  無奈伤痛
    2020-12-06 05:52

    you have to make BLOB to base64_encode

     while($spot = $results->fetch_assoc()){
         $spots[] = $spot;                                                           
        }
    

    Then prepare a foreach loop like this

    foreach($spots as $key=>$value){
        $newArrData[$key] =  $spots[$key];
        $newArrData[$key]['picture'] = base64_encode($spots[$key]['picture']);
        $newArrData[$key]['thumbnail'] = base64_encode($spots[$key]['thumbnail']);
    }
    header('Content-type: application/json');
    echo json_encode($newArrData);
    

提交回复
热议问题