cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Learn all about apps and Dropbox integrations to make working from home easy 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: 

Re: Listing files in a folder, and make download links for all files?

Listing files in a folder, and make download links for all files?

James_T
Helpful | Level 6

I have a private Dropbox.

I have a PHP-driven webpage where i want to list clickable links to some files in a specific folder in my dropbox.

It's simple to list the files on my web page, I just use "files/list_folder/" to get an array of the files in the wanted folder.

 

But how can I get URLs to download the files, so I can make my list of files clickable?

6 Replies 6

Re: Listing files in a folder, and make download links for all files?

Здравко
Super Collaborator | Level 20

Hi @James_T,

Just use sharing/create_shared_link_with_settings. 😉 Existing links could be enumerated with sharing/list_shared_links.

Hope this helps.

Re: Listing files in a folder, and make download links for all files?

macribas
Dropboxer

You need to loop that array and create links for each file. 

Take a look at the /sharing/create_link_with_settings endpoint. 

 

Alternatively, we provide an embedded component to display the contents of a folder directly in a web page:

https://dropbox.tech/developers/now-available--dropbox-embedder

Maybe that will make your life easier. 

Re: Listing files in a folder, and make download links for all files?

James_T
Helpful | Level 6

Won't looping through every file and folder and make a ton of share links be very slow?

 

The embedding solution seems more sensible, but if I understand correctly:

 

1. The root folder must have a share link created first

2. I have no control over which files and folders are displayed (I can't choose to hide a specific subfolder, or a specific file)

 

Re: Listing files in a folder, and make download links for all files?

Greg-DB
Dropboxer

@James_T Yes, /2/sharing/create_shared_link_with_settings requires one call per item, so if there's a significant number to process, that would take a significant amount of time. That being the case, you could also consider only creating the shared link on demand, when the user clicks on a specific file. That is, the listed on your file on your page would link to a route on your server, which when accessed, would make the Dropbox API call and then redirect the user to the returned link. (Likewise, /2/files/get_temporary_link would also work here, if you just need a temporary direct download link instead of a shared link.)

 

Alternatively, if you want to have the user's browser download the file directly, you could use /2/files/download on your server when the user clicks on a particular file. That would require passing the file data through your server each time though.

 

And yes, your understanding of the Embedder is correct. It would take a single shared link for the parent folder, and would then list everything in that linked parent folder.

Re: Listing files in a folder, and make download links for all files?

Здравко
Super Collaborator | Level 20

@James_T wrote:

Won't looping through every file and folder and make a ton of share links be very slow?

...


@Здравко  wrote:
... Existing links could be enumerated with sharing/list_shared_links. ...

If you take care every file you want to show to be associated in advance with a shared link, listing process is just a single API call. 😉 Even more, you can filter the results "on fly" and filter any unwanted entry with a shared link. Is this so slow? 🤔 Probably it depends on your data structure...

Good luck.

Re: Listing files in a folder, and make download links for all files?

James_T
Helpful | Level 6

Thanks for the replies!

 

I think I will go for the Embedder route, even though it has some drawbacks in my case. It really is a shame that the Embedder isn't more customizable. 

 

In our company, we create a root folder for all new projects, with a bunch of subfolders we work on from a PC. On our internal website we want our employees to be able to access the content of only certain of those folders.

 

The problems with the embedder is:
1. The folder needs a share link. Workaround: When creating the project folders, make a share link and save to DB.

2. Sharing the folder gives access to all folders. Workaround: Create a subfolder called "web" and move the folders employees needs access to there, and share that one instead.

 

The second workaround is the biggest problem for us, since that means an extra click into the "web" folder every time we work on our folders from a PC - which we do a lot (for those who don't know, it's also not very logic why some folders are not in the root, while others are)

 

All in all, I think the Embedder route is a better option than spending a bunch of time recreating what is basically a custom version of the embedder, which will never be as nice (previews, icons etc). 

Poll
How do you get refocussed while working from home? Do you find any of these options keep you from getting distracted?
Need more support?