Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

nadeemphpdots's avatar
nadeemphpdots
Explorer | Level 4
4 years ago

Get thumbnails of files from shared folders

Hi there,

I get list of files inside shared folder using "2/files/list_folder" with "shared_link" parameter and I am using response from "2/files/list_folder"  into  "2/files/get_thumbnail_v2" api call to get thumbnails. 
"2/files/get_thumbnail_v2" api return "path/not_found/." error invalid path error.



Is there any other way to achieve this ? 
I want thumbnails of file from shared folder.

  
 

10 Replies

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

    You should be able to use /2/files/get_thumbnail_v2 to get a thumbnail of a file from a shared link for a folder. I just tried it out and it worked for me. Here's an example of what the call might look like for curl, for instance:

    curl -X POST https://content.dropboxapi.com/2/files/get_thumbnail_v2 \
      --header 'Authorization: Bearer <ACCESS_TOKEN>' \
      --header 'Dropbox-API-Arg: {"resource":{".tag":"link","path":"/test.jpg","url":"<SHARED_LINK>"}}' \
      -o out.jpg

    In this example, "/test.jpg" is the relative path of the file for which I want the thumbnail in the linked folder.

     

    If something's not working as expected for you, please show us the steps and code you're using that result in the issue so we can take a look. Make sure to redact any access token though.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    4 years ago

    nadeemphpdots, In addition to what Greg said, you can use those calls also with Application Authentication. In other words, you don't need to be logged in since shared resource isn't something private (by assumption).

    Greg-DB, I thought to post the example in App Authentication section, but there is a mistake. Can you use path in anonymous access, alone?! 😉 Maybe some documentation corrections are need.

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

    Yes, this works with app authentication as well. In that case it would look like:

    curl -X POST https://content.dropboxapi.com/2/files/get_thumbnail_v2 \
      --header "Authorization: Basic <ENCODED_APP_KEY_AND_SECRET>" \
      --header 'Dropbox-API-Arg: {"resource":{".tag":"link","path":"/test.jpg","url":"<SHARED_LINK>"}}' \
      -o out.jpg
  • nadeemphpdots's avatar
    nadeemphpdots
    Explorer | Level 4
    4 years ago

    Hi @Greg-DB, Здравко Thanks for reply,

     I use below code and getting error 

    "Error in call to API function "files/get_thumbnail:2": HTTP header "Dropbox-API-Arg": could not decode input as JSON"

     

                        $ch = curl_init();
    
                        curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/get_thumbnail_v2');
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        curl_setopt($ch, CURLOPT_POST, 1);
    
                        $headers = array();
                        $headers[] = 'Authorization: Bearer sl.BIgvvyUur9m--oAuUapVgE__HaC8DnOZqdWuE9Q0Cs6QfpGbsYtWgAzQI6jGfW_seiBVA8gIeE0FFb0oUBM__kr3Br08XnoMD2EBSv_3g-MqrKibUT4_e6JlwJr_eCDyTMcwkZMm8RWV';
                        $headers[] = 'Dropbox-Api-Arg: {\"resource\":{\".tag\":\"link\",\"url\":\"https://www.dropbox.com/sh/ns2y8e6lqyh5avz/AAAHX5tPck8CHwpcSKMwV7cba?dl=0\",\"path\":\"/1515 Lochstone Drive 8.jpg\"}}';
                        $headers[] = 'Content-Type: application/octet-stream; charset=utf-8';
                        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
                        $result = curl_exec($ch);
                        dd($result);

     

     

  • nadeemphpdots's avatar
    nadeemphpdots
    Explorer | Level 4
    4 years ago

    Hi @Greg-DB,
    I updated code and getting  result like 

    ����JFIF��C  %# , #&')*)-0-(0%()(��C   (((((((((((((((((((((((((((((((((((((((((((((((((((��+@"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?��S���v���0GpjQ&��-�;���v5Q���T�P�4�Z6�dp3XWZ��qG��r�J G`�29���Gr�-��\/�WipMAg���L[�ˡ����0ʞ�}��95 ���%G#/?Ni{H�����#��u�N��p��(G�9���M[M{�g �n�‰*�O��p9��Z�u������r;Ckh�<�r���;����J��*1��_��]ni,4�6 -W,�!�O�8����Ct�j�)`�c ��VU���.��4Km� �Fs���6—W���`�#a����(�z�q�k�:OY�~#��쮰Cm���q]�e{Kx���ъ�;�G��u>��hZ`�N�H��f�`t�?T��u�t��:ItA�xQ��X)ʢ7Q�7���g��Գ�Hm�*��N��wN �t�;C����Ծk/�cm�rh'��خ^K[�E��w��y�V#��#h��֯�WH��l��x̦Y���#=q�[R��&gR���H���/�{!��2�� v�1��&��y����=���L�r� 7/=qבUmt[��L��� ���C���s��+��-l������l���i\�x�<�E� R�m���Ѽ'q�d��J0�D[k�=���u���Z\�#��9������I�V~���jK�~צ�gf=�t m ��L��_z�lX�ߞ���y`�� >�XnL��9��(=kzS�wFSM�xԷ)q�F��T&ߝ��y5ne"M�?�_)\s�� b��V�Z��4V �0�;Q��n��Z�ic>���

    I am trying to display all thumbnails from shared folder in site and User can select particular thumbnail from list and I want to url of that selected thumbnail.

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    4 years ago

    Hi nadeemphpdots,

    Seems you have found out your PHP string error. 🙂.... And... What's wrong here? 🤔 Everything seems normal. Your jpeg, you opened as text, might confuse you. Isn't so? 😉

    Hope this helps.

  • nadeemphpdots's avatar
    nadeemphpdots
    Explorer | Level 4
    4 years ago

    Hi Здравко 
    I am trying to display all thumbnails from shared folder in site and User can select particular thumbnail from list and I want to url of that selected thumbnail.

    Now I will display Image by 

    echo '<img src="data&colon;image/jpg;charset=utf8;base64,'.$data.' />';

    How can I get actual url of image Actual Image ?

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    4 years ago

    😁 I'm not sure you understand, but you are trying to put image file binary content as a source URL of an image. I thought my post above was clear, but seems it's not enough. Think of your "$data" as a content of an image read from file available on your server (not as a URL to there). What will be the result? 🧐 🙂 You have to pass the image data as such not as a URL! There are many correct way this to be done. 😉 Only your imagination ability can restrict you. Of course, there are many wrong ways (like mixing URL and data).

    Hope it's a bit more clear now.

  • nadeemphpdots's avatar
    nadeemphpdots
    Explorer | Level 4
    4 years ago

    Здравко 
    I am able to display thumbnails, But Now I want to open actual image (not thumbnails) on click of particular thumbnail image.
    Is there any api to get both thumbnail and actual image?

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    4 years ago

    nadeemphpdots wrote:

    ...
    Is there any api to get both thumbnail and actual image?


    No, both - no. You already know how to display your thumbnail. For actual image, you can select using shared link, temporary link, or image data (like the thumbnail). Shared link can be created with 2/sharing/create_shared_link_with_settings, temporary link with 2/files/get_temporary_link, and actual image data with 2/files/download. 😉 First 2 give URL, the last one - data! Don't mix them again. 😁

    The choice is yours.

     

    ADD: Actually there is alternative non supported way to get links URL to contained pictures in such a shared folder link. The work of such a hacking way is not guaranteed. Executing something like:

    curl https://www.dropbox.com/sh/ns2y8e6lqyh5avz/AAAHX5tPck8CHwpcSKMwV7cba?dl=0 -H "User-Agent: Mozilla" | xmllint --html --xpath "/html/body/script[last()-1]" - | tr '\n' '\f' | sed 's/.*<script type="text\/javascript".*<!\[CDATA\[.*responseReceived("\(.*\)")});.*\]\]><\/script>.*/\1/' | tr '\f' '\n' | sed 's/\\"/"/g' | sed 's/\\\\/\\/g' | jq

     ... will give you all available data for this shared link. You can filter further this information to get desired data. For example, you can get for every single photo on the shared link its thumbnail and full size picture link/URL using following:

    curl https://www.dropbox.com/sh/ns2y8e6lqyh5avz/AAAHX5tPck8CHwpcSKMwV7cba?dl=0 -H "User-Agent: Mozilla" | xmllint --html --xpath "/html/body/script[last()-1]" - | tr '\n' '\f' | sed 's/.*<script type="text\/javascript".*<!\[CDATA\[.*responseReceived("\(.*\)")});.*\]\]><\/script>.*/\1/' | tr '\f' '\n' | sed 's/\\"/"/g' | sed 's/\\\\/\\/g' | jq '.entries[] | .thumbnail_url_tmpl, .preview.content.full_size_src'

    I believe you can  "translate" the algorithm above to PHP. 🤫😜

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

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!