Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I am using Codeigniter and Phil's REStful API.

I am making a call to the server and the problem is it return a NULL value. The value that should be return is a blob that is 65000 in length. I reckon its because of the length of the blob, but I don't know how to solve this issue.

Here's how i call the 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;
}

Here's the method:

    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); 

    }

}
share|improve this question

1 Answer 1

I'm not fully sure of the solution, but I do this when trying to solve REST bugs with the libary:

You can output:

$this->response($_SERVER);

and

$this->response($_POST);

etc. to see all the server variables, so you can check the length of the response and the headers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.