Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Mike V.15's avatar
Mike V.15
New member | Level 1
10 years ago

Why do I get this as response for file Download?

I'm using the HTTP API with PHP via it's cURL methods. I send in the correct way the request and I get a correct status (200). But as response from the request I expected the content of the file and I receive strings as this one:

@/tmp/php5BHw8P;filename=8jh7d5.jpg;type=image/jpeg

Am I doing something wrong?

What should I do with this string?

 

I'm doing something like this:

 

$curl = curl_init($url);
$aPostData = array('path' => '/Example.jpg');
$aOptions = CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array('Content-Type: ', // To force empty Content-type
'Authorization: Bearer ' . $sAccessToken,
'Dropbox-API-Arg: ' . json_encode($aPostData)
),
CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($curl, $aOptions);
$result = curl_exec($curl); // $result = '@/tmp/php5BHw8P;filename=8jh7d5.jpg;type=image/jpeg'
.
.
.

3 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    I cleaned up your code and tried this:

    <?php

    $url = "https://content.dropboxapi.com/2/files/download";
    $sAccessToken = "ACCESS_TOKEN_HERE";
    $curl = curl_init($url);
    $aPostData = array('path' => '/PATH_TO_IMAGE_HERE.jpg');
    $aOptions = array(
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => array('Content-Type: ', // To force empty Content-type
    'Authorization: Bearer ' . $sAccessToken,
    'Dropbox-API-Arg: ' . json_encode($aPostData)
    ) ,
    CURLOPT_RETURNTRANSFER => true
    );
    curl_setopt_array($curl, $aOptions);
    $result = curl_exec($curl);

    $fp = fopen('out.jpg', 'w');
    fwrite($fp, $result);
    fclose($fp);

    ?>

    That works fine for me and produces the image file I expect.

    Does this work for you too? Is the actual code you're using different?

  • Mike V.15's avatar
    Mike V.15
    New member | Level 1
    10 years ago

     

     

     

     

    Today I copied your code and hardcoded my access token and my file path.

     

    I got this:


    ></p>
<p>There could be something wrong with my server?</p>

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    Actually, it seems like the code is working correctly, and that string is the contents of the file you're trying to download. You can double check this by downloading it manually via the Dropbox web site.

About Dropbox API Support and Feedback

Node avatar for Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!