我正在使用 Codeigniter 和 Phil 的 RESTful API。
我正在调用服务器,问题是它返回一个 NULL 值。应该返回的值是一个长度为 65000 的 blob。我认为它是因为 blob 的长度,但我不知道如何解决这个问题。
这是我调用api的方式:
$resp = call('upload_api/upload/format/json/', array('uploaded_files' => $_FILES['upload'], 'file_details' => 'test'));
echo '<pre>'; print_r($resp);
public static function call($resource, $params, $method='get')
{
if (empty($params))
{
$params = array();
}
$headers = '';
$url = self::API_URL . $resource;
$curlObj = curl_init();
curl_setopt_array($curlObj,
array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20
));
switch ($method)
{
case 'get':
$query_str = http_build_query($params);
$url = $url .= '?' . $query_str;
curl_setopt($curlObj, CURLOPT_URL, $url);
break;
case 'put':
$headers[] = 'Content-Type: application/json';
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlObj, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curlObj, CURLOPT_POSTFIELDS, json_encode($params));
break;
case 'post':
$headers[] = 'Content-Type: application/json';
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlObj, CURLOPT_POST, true);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, json_encode($params));
break;
default:
// error message
}
$data = curl_exec($curlObj);
$contentType = curl_getinfo($curlObj, CURLINFO_CONTENT_TYPE);
switch ($contentType)
{
case 'application/json':
$data = json_decode($data, true);
break;
}
curl_close($curlObj);
return $data;
}
这是方法:
require APPPATH.'/libraries/REST_Controller.php';
class Upload_api extends REST_Controller {
public function upload_get()
{
$this->load->model('Upload_File');
$upload_file = new Upload_File();
$total_rows = $upload_file->count();
$upload_file->get(1, 0)->all;
// file_content is a blob
$this->response(array('file' => $upload_file->file_content, 'total_rows' => $total_rows), 200);
}
}