Forum Discussion

rahulsharma1902's avatar
rahulsharma1902
Explorer | Level 4
2 years ago

Use API get image name from dropbox and display in html img tag

I get image name and id from drop box using api 
But now I don't know how I can use this image name in img tag can you give me a public url according to that I can display this image in my html <img> tag ?

 

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

    rahulsharma1902 wrote:

    I get image name and id from drop box using api 
    But now I don't know how I can use this image name in img tag ...


    Hi rahulsharma1902,

    You can use this image name in img tag as far as you could for any other file from any other place 🙋 (i.e. you cannot).

     


    rahulsharma1902 wrote:

    ... can you give me a public url according to that I can display this image in my html <img> tag ?


    You can use either /2/files/get_temporary_link or /2/sharing/create_shared_link_with_settings (whatever better match to your use case) or their SDKs equivalents (if you use some). Keep in mind that using shared link requires transformation from preview link (the default one) to raw link! Forgetting this will lead to unusable HTML.

    Happy new year and hope this gives direction.

    • rahulsharma1902's avatar
      rahulsharma1902
      Explorer | Level 4

      I have more query :
      1. I am using access token to get image link but the access token is expire within some hours how I get long term access token ?
      2. Second one Is client give me client ID and secret Id and redirect URL  but when I use these credential in my device this give me error but when I replace these with my Dropbox app credential then they work fine ? should we use them in our device

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

        rahulsharma1902, Dropbox API doesn't issue long lived access token anymore. All access token issuing at present are short lived and remain valid for 4 hours or so. For long term access, you need refresh token that doesn't expire automatic and can be used repeatedly whenever needed to "refresh" (regenerate actually) access token.

        Don't mess application authentication and account (user) authentication (as you're doing)! They are different things and usually one of them cannot replace the other (as you're trying). Application authentication (app key and app secret) authenticates the application itself (as the name suggests), not some account (including the one associated with the application). Such authentication can be used only for activity unrelated to particular account content, but only to content public accessible already (like some shared links related operations). To perform account access, you need corresponding account related authentication that represent account owner granting for your application to manage the content (including your own) - access and refresh tokens.

        You can let the user (again, including to yourself) to grant access permissions to your application to access owned account using OAuth flow (take a look here for a simplest example). In such a way your application ask the user for permission to access the content. Here you can Note offline access that will result in adding refresh token. If you're using some supported SDK initializing the client object properly using refresh token is enough (you don't need to perform refresh yourself), otherwise the last step in the post I linked to be comes your responsibility.

        Hope this helps.

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers803 PostsLatest Activity: 3 hours ago
216 Following

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 or Facebook.

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!