3

So the Dropbox API is weird when "Downloading a file" with the Python version. It gives metadata about the file, but it doesn't actually download the file. Which is weird considering their API documentation says files_download(path) says it will download a file from a Dropbox when it just gets metadata.

k = dbx.files_get_temporary_link('/' + str(message))

This is a line of code that will bypass the files_download but where Metadata stops, more begins. When ran, it will throw out this class:

GetTemporaryLinkResult(metadata=FileMetadata(name='buiEKTw.png', id='id:8ZPbLGM5GIAAAAAAAAAACg', client_modified=datetime.datetime(2016, 11, 22, 1, 26, 27), server_modified=datetime.datetime(2016, 11, 22, 1, 26, 27), rev='e5047428b', size=905, path_lower='/buiektw.png', path_display='/buiEKTw.png', parent_shared_folder_id=None, media_info=None, sharing_info=None, property_groups=None, has_explicit_shared_members=None), link='https://dl.dropboxusercontent.com/apitl/1/AAAzE5ljMmZZ8jxjcKAh_uIym9Hy7tfC4Z67zvzMpakZDqhoje2BgXE9bTz1-dyy2QIuQJbJKiVfD1RvY4PI4AS1sPhTDRSgqpXMU7XBasZ_gw5lNEpyGiYM-m5lQDozXf6oP7WAJjb1NqwRlQuPfRHpsJq7PRn4alBddVdzb6MZTyBdlvzd55hcxqhbU3d9o84mOR9qGh3zl6rSzYUWbhr7RoQVscpq2qug-lnTelc9eQ')

I just want the link at the end of the class/metadata and I can't seem to get it. The link itself is 280 characters and with the quotes is 282. And the metadata is subject to change everytime it gets the metadata.

1
  • 1
    Have you tried k.link or k.link() ? Commented Nov 23, 2016 at 2:34

1 Answer 1

7

The files_get_temporary_link method returns a GetTemporaryLinkResult. As sal commented, you can use .link to access the link from that object, like this:

result = dbx.files_get_temporary_link(filePath)

print(result.link)

Note that that method returns a link to the file. If you want to access the file content directly, you can use files_download as shown below:

This uses the Dropbox Python SDK to download a file from the Dropbox API at the remote path /Homework/math/Prime_Numbers.txt to the local file Prime_Numbers.txt:

import dropbox
dbx = dropbox.Dropbox("<ACCESS_TOKEN>")

with open("Prime_Numbers.txt", "wb") as f:
    metadata, res = dbx.files_download(path="/Homework/math/Prime_Numbers.txt")
    f.write(res.content)

<ACCESS_TOKEN> should be replaced with your access token.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.