将文件从保管箱下载到服务器


Download file from dropbox to the server

我想从 Dropbox 下载文件,需要代表 Dropbox 用户将其保存在我的服务器中。我尝试了卷发和file_get_contents。但未能成功。我是否需要使用保管箱的任何 api 方法?我可以从浏览器下载文件,但我需要将其保存在服务器中。我的应用程序是一种文件共享。

您可以使用

指向该文件的 Dropbox 公共链接,并使用 file_get_contentsfile_put_contents 。下面的香草 PHP 示例。

<?php
    // Custom Dropbox link. Notice the ?dl=1 at the end. 
    $url = file_get_contents( 'https://www.dropbox.com/s/hash/file.mp4?dl=1' );
    // Your new file name 
    $file = "downloaded-video.mp4";
    // open, write and close the new file
    file_put_contents($file, $url);
?>
来自

服务提供商的 API 通常是访问其数据的最佳方式。这种方法肯定会更好。

我唯一的注意事项是:小心不要破坏Dropbox的ToS。

Dropbox 浏览器客户端仅供注册用户使用,用户需要登录,然后才能访问其中的文件。

但正如你所说,你想代表用户访问Dropbox文件,你需要利用Dropbox Core API,你可以使用PHP Dropbox SDK来构建自己的应用。我认为没有其他办法。

正如您提到的,您想代表用户从 Dropbox 访问文件,我想您可能会在没有用户交互的情况下想到它,但有一个问题,Dropbox 使用 OAuth 1.0 或 2.0,在这两种方法中,您都需要进行用户交互。(欲了解更多信息,请阅读此处)

你也说你的应用是一种File Sharing,所以一定要看看Dropbox应用审核流程,它禁止公开搜索File Share应用。

不要构建文件共享应用

Dropbox

不支持在 Dropbox 之上构建可公开搜索的文件共享网络。

Dropbox

选择器是从 Dropbox 获取文件的最快方式

https://www.dropbox.com/developers/chooser

在演示部分下,选择直接链接,然后选择保管箱文件以创建直接链接。

登录到SSH并导航到要下载并粘贴命令的文件夹

curl -O 'url'

你可以使用/download。 它将返回如下响应:

{
"name": "Prime_Numbers.txt",
"id": "id:a4ayc_80_OEAAAAAAAAAXw",
"client_modified": "2015-05-12T15:50:38Z",
"server_modified": "2015-05-12T15:50:38Z",
"rev": "a1c10ce0dd78",
"size": 7212,
"path_lower": "/homework/math/prime_numbers.txt",
"path_display": "/Homework/math/Prime_Numbers.txt",
"sharing_info": {
    "read_only": true,
    "parent_shared_folder_id": "84528192421",
    "modified_by": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
},
"property_groups": [
    {
        "template_id": "ptid:1a5n2i6d3OYEAAAAAAAAAYa",
        "fields": [
            {
                "name": "Security Policy",
                "value": "Confidential"
            }
        ]
    }
],
"has_explicit_shared_members": false,
"content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"

}

在此处查看完整详细信息:https://www.dropbox.com/developers/documentation/http/documentation#files-download