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 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码