如何制作文件以强制在Dropbox SDK中下载 [英] how to make a file to force download in dropbox sdk

查看:61
本文介绍了如何制作文件以强制在Dropbox SDK中下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dropbox php sdk,我想通过浏览器下载文件。我有一个文件预览链接,但现在不了解如何下载文件。我正在使用函数

I am using dropbox php sdk and i want to download the file through the browser . I have a file preview link But away to understand how can i download the file . I am using the function

function GetLink($dropbox_file, $preview=true, $short=true, &$expires=null)
    {
        if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
        $url = $this->apiCall(($preview?"shares":"media")."/$this->rootPath/$dropbox_file", "POST", array('locale' => null, 'short_url'=> $preview ? $short : null));
        $expires = strtotime($url->expires);
        return $url->url;
    }

这会产生一个链接,用于预览文件,如 https://db.tt/S3znA2kE ,如果我打开此链接,它将变成 https://www.dropbox.com/s/64h549xaofsm67p/readme.txt
i知道文件可以下载吗? dl = 1但不了解如何操作

and this is producing a link to preview the file like https://db.tt/S3znA2kE and if i open this link it becomes https://www.dropbox.com/s/64h549xaofsm67p/readme.txt i know file can download if i will pass ?dl=1 but can't understand HOW

推荐答案

两种可能性:


  1. 您可以停止在 short 参数中传递 true,从而获得一个较长的URL。然后,您可以直接使用 dl = 1 参数。

  2. 如果由于某种原因需要获取一个短网址,然后可以通过执行HTTP HEAD并查看返回的 Location 标头来扩展它。例如。 (使用 curl ):

  1. You could stop passing "true" in the short parameter and thus get a long URL to start with. Then you can just use the dl=1 parameter directly.
  2. If, for some reason, you need to get a short URL, you could then expand it by doing an HTTP HEAD and looking at the returned Location header. E.g. (using curl):

$ curl -I https://db.tt/S3znA2kE
HTTP/1.1 302 FOUND
Server: nginx
Date: Thu, 07 Aug 2014 21:16:19 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
location: https://www.dropbox.com/s/64h549xaofsm67p/readme.txt
pragma: no-cache
cache-control: no-cache

具有完整的扩展URL后,可以对其进行修改以使用 dl = 1 参数。

After you have the full expanded URL, you can modify it to use the dl=1 parameter.

这篇关于如何制作文件以强制在Dropbox SDK中下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆