1

I´m trying to upload a file from PHP via Box-API v2 and I only get a boolean false response. I think this is caused by CURL, not Box-API but I was fighting the last five hours, and I can´t find the solution. Any idea?? The implicated code is that: note: the file exists and is accessible from code and the token is ok (other calls to API work fine)

const CONTENT_ENDPOINT = 'https://api.box.com/2.0/';
$file = "unexeceles.xlsx";

private $defaultOptions = array(
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_VERBOSE        => true,
        CURLOPT_HEADER         => true,
        CURLINFO_HEADER_OUT    => false,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => false,
    );    

public function putFile($file) {

        $options = $this->defaultOptions;
        $options[CURLOPT_HTTPHEADER] = array ("Authorization: Bearer ".$this->token);
        $options[CURLOPT_POST] = true;
        $postfields = array();
        $postfields["filename"] = '@'.$file;
        $postfields["parent_id"] = 0;

        $options[CURLOPT_POSTFIELDS] = $postfields;
        $handle = curl_init(BoxConfig::CONTENT_ENDPOINT."files/content");

        curl_setopt_array($handle, $options);

        $response = curl_exec($handle);

        curl_close($handle);
        if (is_string($response)) {
            $response = $this->parse($response);
        }

        return $response;
    }

1 Answer 1

1

Finally I've found the solution.

The problem was the relative path to the file, the file exists and it´s accessible form code, but CURL seems to need the entire path to the file.

Very helpful the function curl_errno($handle)

if(curl_errno($handle)) {

echo 'Curl error: ' . curl_error($handle); 

}

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.