We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
Aryahagh
5 years agoNew member | Level 2
Reading programmatically several files from Dropbox business
Hi
I want to read (or only reading is not possible, download) several files in different folders ,which is stored in a Dropbox buisiness account, programmatically in python. I were able to create a...
- 5 years ago
If you only want to access the files in one particular account, you can register a "Dropbox API" app with the "Full Dropbox" permission and then use the /2/files/download endpoint to download files from a connected account without any extra configuration. (You can also connect the app to multiple different accounts, but each user would need to authorize their own account, to give the app a distinct access token for each one.) That would look like this:
curl -X POST https://content.dropboxapi.com/2/files/download \ --header "Authorization: Bearer <ACCESS_TOKEN>" \ --header "Dropbox-API-Arg: {\"path\": \"/test.txt\"}"
Or, using the Python SDK:
dbx = dropbox.Dropbox(ACCESS_TOKEN) print(dbx.files_download("/test.txt"))
If you want to be able to access the files any team member's account on a Business team, by only having a team admin authorize the app once, you will need to register a "Dropbox Business API" app with the "team member file access" permission and then use the /2/files/download endpoint to download files, but with some extra configuration as covered in the "Member file access" section of the Business API documentation. Since Dropbox Business API apps are connected to the entire Business team, you need to specify which member you want to operate on when making a user-level call, such as /2/files/download. You can do so by specifying the Dropbox-API-Select-User" header with the value being the team member ID of the member you want to call for. The team member ID starts with "dbmid:" and can be retrieved from the Dropbox Business API, such as via /2/team/members/get_info or /2/team/members/list[/continue]. That would look like this:
curl -X POST https://content.dropboxapi.com/2/files/download \ --header "Authorization: Bearer <TEAM_ACCESS_TOKEN>" \ --header "Dropbox-API-Select-Admin: <TEAM_MEMBER_ID>" \ --header "Dropbox-API-Arg: {\"path\": \"/test.txt\"}"
Or, using the Python SDK:
dbx = dropbox.DropboxTeam(TEAM_ACCESS_TOKEN).as_user(TEAM_MEMBER_ID) print(dbx.files_download("/test.txt"))
Greg-DB
Dropbox Staff
If you only want to access the files in one particular account, you can register a "Dropbox API" app with the "Full Dropbox" permission and then use the /2/files/download endpoint to download files from a connected account without any extra configuration. (You can also connect the app to multiple different accounts, but each user would need to authorize their own account, to give the app a distinct access token for each one.) That would look like this:
curl -X POST https://content.dropboxapi.com/2/files/download \ --header "Authorization: Bearer <ACCESS_TOKEN>" \ --header "Dropbox-API-Arg: {\"path\": \"/test.txt\"}"
Or, using the Python SDK:
dbx = dropbox.Dropbox(ACCESS_TOKEN) print(dbx.files_download("/test.txt"))
If you want to be able to access the files any team member's account on a Business team, by only having a team admin authorize the app once, you will need to register a "Dropbox Business API" app with the "team member file access" permission and then use the /2/files/download endpoint to download files, but with some extra configuration as covered in the "Member file access" section of the Business API documentation. Since Dropbox Business API apps are connected to the entire Business team, you need to specify which member you want to operate on when making a user-level call, such as /2/files/download. You can do so by specifying the Dropbox-API-Select-User" header with the value being the team member ID of the member you want to call for. The team member ID starts with "dbmid:" and can be retrieved from the Dropbox Business API, such as via /2/team/members/get_info or /2/team/members/list[/continue]. That would look like this:
curl -X POST https://content.dropboxapi.com/2/files/download \ --header "Authorization: Bearer <TEAM_ACCESS_TOKEN>" \ --header "Dropbox-API-Select-Admin: <TEAM_MEMBER_ID>" \ --header "Dropbox-API-Arg: {\"path\": \"/test.txt\"}"
Or, using the Python SDK:
dbx = dropbox.DropboxTeam(TEAM_ACCESS_TOKEN).as_user(TEAM_MEMBER_ID) print(dbx.files_download("/test.txt"))
Aryahagh
5 years agoNew member | Level 2
Thanks Greg,
By the way I was able to download data from the dropbox by these solutions using following command :
dbx.files_download(path="PATHtoFILE")
However I didn't find a way to only read the document without downloading it. What I want to do is opening a .txt file and read a certain line in it or open a video and get only one frame of it without downloading the whole video. Is there any way to do that?
Thanks again
- Greg-DB5 years agoDropbox Staff
The files_download method returns a tuple of (FileMetadata, requests.Response), so you can get the file data from requests.Response using the methods provided by that class.
For instance, you can stream content from it piece by piece, without downloading the whole thing, using requests.Response.iter_content and/or requests.Response.iter_lines, if those work for your use case. As a contrived example:
metadata, res = dbx.files_download("/test.txt") for data in res.iter_lines(): print(data) raw_input()
That sounds like that isn't exactly what you're looking for though unfortunately, as the iter_lines method returns a generator that lets you run through the lines; it doesn't let you retrieve a specific line. Likewise, iter_content wouldn't let you retrieve a specific video frame from an arbitrary location in a video file.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 2 months agoIf 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!