cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right 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: 

How to display thumbnails in it's original size with PHP

How to display thumbnails in it's original size with PHP

lrduques
Helpful | Level 6
Go to solution

Hi! 

I am trying to display my Dropbox images on the browser using /get_thumbnail which works just fine.

However, the image on the browser it's too small. It's not the original size.

This is the png image on my Dropbox account:

test.PNG

And this is the same image I got from the API:

test-2.png

As you can see, it's impossible to see the image.

So anyone knows how do I get the image in it's original size? I am using a PHP code as follow to browser the images:

<?php 

require_once 'Functions/functions.php';

header("Content-Type: image/jpeg");

$token = getToken($_SESSION['uid']);

if (isset($token[0])) {

    //$data  = file_get_contents('json/getThumbnail.json');

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token[0]->itoken, 'Dropbox-API-Arg: {"path": "/test-1/Capture-desktop.PNG", "format": "png", "mode": "strict"}'));
    curl_setopt($ch, CURLOPT_URL, "https://content.dropboxapi.com/2/files/get_thumbnail");
    
    $response = curl_exec($ch);

    echo $response;

}else{
    header('Location: http://localhost/optiSurface-dropbox/curl-auth1.php');
    exit();
}

 ?>

I appreciate if anyone can help me out with this issue.

Cheers!! 

2 Accepted Solutions

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

By default, the /2/files/get_thumbnail endpoint will return a 64x64 thumbnail of the requested image. If you want a different size, you can request it using the "size" parameter. You can specify that the same way you specify the "mode" and "format" parameters. You can find more information, such as the sizes that are available, in the /2/files/get_thumbnail:

https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail

Note that if you want the original file data though, you can instead use /2/files/download:

https://www.dropbox.com/developers/documentation/http/documentation#files-download

View solution in original post

lrduques
Helpful | Level 6
Go to solution

Problem solved!! 

I read a little further the documentation I figured out that I was missing the paramenter size on my code.

So I changed this line:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token[0]->itoken, 'Dropbox-API-Arg: {"path": "/test-1/Capture-desktop.PNG", "format": "png", "mode": "strict"}'));

For this one:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token[0]->itoken, 'Dropbox-API-Arg: {"path": "/test-1/Capture-desktop.PNG", "format": "png", "size": "w1024h768", "mode": "strict"}'));

The size options I found in this link: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail

Capture2.PNG

And now it's working perfectly!

Cheers!!

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

By default, the /2/files/get_thumbnail endpoint will return a 64x64 thumbnail of the requested image. If you want a different size, you can request it using the "size" parameter. You can specify that the same way you specify the "mode" and "format" parameters. You can find more information, such as the sizes that are available, in the /2/files/get_thumbnail:

https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail

Note that if you want the original file data though, you can instead use /2/files/download:

https://www.dropbox.com/developers/documentation/http/documentation#files-download

lrduques
Helpful | Level 6
Go to solution

Problem solved!! 

I read a little further the documentation I figured out that I was missing the paramenter size on my code.

So I changed this line:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token[0]->itoken, 'Dropbox-API-Arg: {"path": "/test-1/Capture-desktop.PNG", "format": "png", "mode": "strict"}'));

For this one:

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token[0]->itoken, 'Dropbox-API-Arg: {"path": "/test-1/Capture-desktop.PNG", "format": "png", "size": "w1024h768", "mode": "strict"}'));

The size options I found in this link: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail

Capture2.PNG

And now it's working perfectly!

Cheers!!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    lrduques Helpful | Level 6
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?