Toniq
Toniq

Reputation: 5006

Dropbox api gets direct file url for streaming

I am using dropbox api to lest files in public folder with endpoint https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder

https://api.dropboxapi.com/2/files/list_folder

Response is something like this:

{
"entries": [
    {
        ".tag": "file",
        "name": "01.mp4",
        "path_lower": "/video/01.mp4",
        "path_display": "/video/01.mp4",
        "parent_shared_folder_id": "3022865105",
        "id": "id:FDeU6KOzmRUAAAAAAAAABw",
        "client_modified": "2022-09-14T15:54:42Z",
        "server_modified": "2022-09-14T16:06:36Z",
        "rev": "5e8a55037c991b42d42d1",
        "size": 12347528,
        "sharing_info": {
            "read_only": false,
            "parent_shared_folder_id": "3022865105",
            "modified_by": "dbid:AACtZetM6hKYpGsPZvtNDZUFRldH8r35OSk"
        },
        "is_downloadable": true,
        "content_hash": "7e6d5e0d1947523808762a6fc34fec7651393ef9d4f4ea2a64fb71acaf3a1240"
    },
    {
        ".tag": "file",
        "name": "02.mp4",
        "path_lower": "/video/02.mp4",
        "path_display": "/video/02.mp4",
        "parent_shared_folder_id": "3022865105",
        "id": "id:FDeU6KOzmRUAAAAAAAAACA",
        "client_modified": "2022-09-14T15:54:42Z",
        "server_modified": "2022-09-14T16:06:36Z",
        "rev": "5e8a55037c992b42d42d1",
        "size": 18791452,
        "sharing_info": {
            "read_only": false,
            "parent_shared_folder_id": "3022865105",
            "modified_by": "dbid:AACtZetM6hKYpGsPZvtNDZUFRldH8r35OSk"
        },
        "is_downloadable": true,
        "content_hash": "93d33bf10fa4e5c340dac84ebafb54d0b2759cc6e801da8ab03ae14783365fac"
    }
],
"cursor": "AAGUGbHG7ju_3pegzOTPruYbexWxEXYyJGNt5Rt1Frj8QAj_JFDTwppfDTneAq-pMfGEbX4i-aDRndn8j-MrAiLy4mCUDc8-GU_XsUdAoShGXtzWKDsDaQwWCHFmhOo0bBuXElarr3Rdil9pTMqkMcfG2hSZPeepDL_omI0Oo0a-_suATq_zoBrH-o2zNKe9-udR2UrsgPuMl9toei-Tt19FCLHX4uzyT6xAXJjFKnWdfj7y3lgyoxrJqtQPVBc1WT0",
"has_more": false
}

My question is how do I get a direct url link to each file in such a way that I can use it in (let's say) an html5 video tag?

When I right click on a file inside a dropbox folder, the url is something like this:

https://www.dropbox.com/s/305pjdhly2w948y/01.mp4?dl=0

How do I get a direct url like this from this response?

Upvotes: 0

Views: 856

Answers (1)

Greg
Greg

Reputation: 16930

The Dropbox API doesn't offer a way to get such links in bulk. You'll need to make a call to make a link for each file.

To get temporary direct link for a file, you would call /2/files/get_temporary_link:

https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link

The Dropbox API doesn't offer a non-temporary version of that exactly, but you can create a shared link via /2/sharing/create_shared_link_with_settings:

https://www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_settings

Or to retrieve existing shared links, use /2/sharing/list_shared_links:

https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_shared_links

That's the same kind of link as returned by the Dropbox web site.

Note that these shared links don't link directly to the file data though. They link to the HTML preview page for the file. You can modify them for direct or raw file access instead though as documented here:

https://help.dropbox.com/share/force-download

Upvotes: 1

Related Questions