如何从 Dropbox Chooser 获取文件的直接链接

问题描述 投票:0回答:1

Dropbox Chooser的文档中,我们可以从

files[0].link
获取共享页面网址,但我们需要直接下载链接。我怎样才能得到它?

dropbox
1个回答
4
投票

我在论坛找到了解决方案。

为 Dropbox 选择器按钮添加了

data-link-type="direct"
属性。

<input type="dropbox-chooser" name="selected-file" data-link-type="direct" style="visibility:hidden"/>

更新 2024年,这就是你需要使用的。

linkType="direct"
为您提供 Dropbox Chooser 中所选文件的直接下载 URL。

let options = {
    linkType: "direct",

    // Required. Called when a user selects an item in the Chooser.
    success: function(files) {
        alert("Here's the direct file link: " + files[0].link)
    },

    // Optional. Called when the user closes the dialog without selecting a file
    // and does not include any parameters.
    cancel: function() {

    },
    
    // Optional. A value of false (default) limits selection to a single file, while
    // true enables multiple file selection.
    multiselect: false, // or true

    // Optional. This is a list of file extensions. If specified, the user will
    // only be able to select files with these extensions. You may also specify
    // file types, such as "video" or "images" in the list. For more information,
    // see File types below. By default, all extensions are allowed.
    extensions: ['.pdf', '.doc', '.docx'],

    // Optional. A value of false (default) limits selection to files,
    // while true allows the user to select both folders and files.
    // You cannot specify `linkType: "direct"` when using `folderselect: true`.
    folderselect: false, // or true

    // Optional. A limit on the size of each file that may be selected, in bytes.
    // If specified, the user will only be able to select files with size
    // less than or equal to this limit.
    // For the purposes of this option, folders have size zero.
    sizeLimit: 1024, // or any positive number
};

var button = Dropbox.createChooseButton(options);
document.getElementById("container").appendChild(button);

来源 - https://www.dropbox.com/developers/chooser

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.