cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Downloading a file from a shared folder PHP CURL

Downloading a file from a shared folder PHP CURL

rasbox
New member | Level 2

I have a business account and we have files in a shared folder. I currently can list of files within folder and this is an example of response I get 

 

 

 #items: array:500 [▼
    0 => array:12 [▼
      ".tag" => "file"
      "name" => "file.mp4"
      "parent_shared_folder_id" => "8693457712"
      "id" => "id:6_UMBoPQ5zAAAAAAAAAqcQ"
      "client_modified" => "2020-04-26T00:17:02Z"
      "server_modified" => "2020-11-19T14:20:38Z"
      "rev" => "015b4766e9661ac00000002062ba330"
      "size" => 1952676954
      "sharing_info" => array:3 [ …3]
      "is_downloadable" => true
      "has_explicit_shared_members" => false
      "content_hash" => "4e9217a7937cfae02cdb41d4baf9b1126f555729ee2a38a0b82d9d27ac320bae"
    ]

Now, everytime I try to download the file from dropbox to a local path I get folder not found. 

 

 

I'm using function below: 

 

 

  function dbx_get_file($token, $in_filepath, $out_filepath)
    {
        $out_fp = fopen($out_filepath, 'w+');
        if ($out_fp === FALSE)
            {
            echo "fopen error; can't open $out_filepath\n";
            return (NULL);
            }

        $url = 'https://content.dropboxapi.com/2/files/download';

        $header_array = array(
            'Authorization: Bearer ' . $token,
            'Content-Type:',
            'Dropbox-API-Arg: {"path":"' . $in_filepath . '"}',
            'Dropbox-Api-Select-User: dbmid:ffffffffff-fhfdjkfhkjfdshkj'

        );

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
        curl_setopt($ch, CURLOPT_FILE, $out_fp);

        

        $metadata = null;
        curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $header) use (&$metadata)
            {
            $prefix = 'dropbox-api-result:';
            if (strtolower(substr($header, 0, strlen($prefix))) === $prefix)
                {
                $metadata = json_decode(substr($header, strlen($prefix)), true);
                }
            return strlen($header);
            }
        );

        $output = curl_exec($ch);

        if ($output === FALSE)
            {
            echo "curl error: " . curl_error($ch);
            }

        curl_close($ch);
        fclose($out_fp);

        return($metadata);
    } 
    

Now issue is path. 

 

Assuming my folder name is "My Company", what would be the path? I've tried below patterns

 

  • foldername/filename
  • parent_shared_folder_id/filename
  • parent_shared_folder_id/file id
  • /
  • null

And I keep getting path not found. Has anyone having the same issue?

 

 

 

1 Reply 1

Greg-DB
Dropbox Staff

It looks like the file isn't being found because the API call doesn't have the correct root. That is, it seems like this file is in your team space, but by default API calls operate in the team member folder, not the team space. You can configure calls to access the team space though, by setting the 'Dropbox-API-Path-Root' header. Please read the Team Files Guide for information on using this functionality.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?