doudouwd2017 2014-08-07 10:25
浏览 49
已采纳

如何在dropbox 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;
    }

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

  • 写回答

2条回答 默认 最新

  • doulu4976 2014-08-07 21:18
    关注

    Two possibilities:

    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
      

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!