Forum Discussion

ashoka's avatar
ashoka
New member | Level 2
7 years ago

Issue in get preview api v2

Error in call to API function "files/get_preview": The request body is supposed to be empty, but it isn't; got "{\"path\":\"\\/2019_DB\\/Copies\\/A123\\/NEW\\/21004_1910036125.pdf\"}"

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $auth_token, "Content-Type : application/x-www-form-urlencoded"));
//curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings");
//curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/files/get_temporary_link");
curl_setopt($ch, CURLOPT_URL, "https://content.dropboxapi.com/2/files/get_preview");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('path'=> $file_path)));
$result = curl_exec($ch);
print_r($result);

 

I tried with content-type : application:pdf as well

 

I want to view file in browser or iframe

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    This error message is indicating that you're supply a request body with this API call, but the API expects the request body to be empty.

     

    That's expected per the documentation for /2/files/get_preview, which indicates that it's a "Content-download" style endpoint. The documentation there covers this in more detail, but in short, you should be sending the API call parameters in a 'Dropbox-API-Arg' header, not the request body.

     

    To fix this, update your code to send the parameters in a 'Dropbox-API-Arg' header, instead of in the request body, as you're currently doing with 'CURLOPT_POSTFIELDS'.