You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

NavPanchhi's avatar
NavPanchhi
Explorer | Level 3
3 years ago

Simple file name retrieving using javascript

Hello,

I'm really new to working with the dropbox API and was completely lost on how to retrieve file names. My main goal is to just have a list of the files' names that are uploaded to Dropbox display on my website as simple text. I've tried using the chooser that was in the documentation but I can't seem to get the file names. I just get the popup window (and no alert). So far this is the only code I have. I'm genuinely lost on this. Any help would be great

<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="************"></script>

<script>

options = {
success: function(files) {
console.log(files[0].name);
alert("Here's the file link: " + files[0].link);
},
cancel: function() {
linkType: "direct",
multiselect: false,
folderselect: false
sizeLimit: 1024,

};
Dropbox.choose(options);

</script>

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    The Dropbox Chooser is a way to allow end-users to select specific files/folders and send them to the app. Based on your description, it sounds like that's not exactly what you're looking for. The Dropbox Embedder might be a better solution for you though. That lets you supply a (view-only) shared link, e.g., for a particular folder, and displays the contents of that folder on a web site.

     

    Alternatively, if you need a more custom integration, you would need to use the Dropbox API instead. That allows you to programmatically list files and folders. For example, to list the contents of any particular folder, you would use the /2/files/list_folder[/continue] endpoints to list the contents of a specific path, and the results would include the name of each item. By the way, those are links to the documentation for the HTTPS endpoints themselves, but we recommend using one of the official SDKs if possible. Those have corresponding native methods for the HTTPS endpoints. The Getting Started and File Access guides may also helpful if you decide to use this option.

    • NavPanchhi's avatar
      NavPanchhi
      Explorer | Level 3

      Hello,

       

      I am currently using the ajaz call below to achieve what I need but am still facing issues.

       

      $.ajax({
      type: 'POST',
      url: 'https://api.dropboxapi.com/2/files/get_metadata',
      data: "{\"include_deleted\":false,\"include_has_explicit_shared_members\":false,\"include_media_info\":false,\"path\":\""}",
      contentType: "application/json",
      beforeSend: function(xhr) {
      xhr.setRequestHeader("Authorization", "Bearer ***")
      }, success: function(data){
      console.log(data);
      }
      })

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Please clarify what you mean when you say you are "still facing issues". For example, share any unexpected error or output.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,910 PostsLatest Activity: 2 days ago
333 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!