【问题标题】:Box 2.0 API download call not showing download link to dl.boxcloud.com in POSTMAN or cURLBox 2.0 API 下载调用未在 POSTMAN 或 cURL 中显示 dl.boxcloud.com 的下载链接
【发布时间】:2013-03-15 21:04:05
【问题描述】:

我正在尝试通过 POSTMAN 的 BOX API 下载图像文件。文件id是6917417032

我的代码是: https://api.box.com/2.0/files/6917417032/content 我在标题中指定了授权码

文档指出: 退货 如果文件可供下载,则响应将是 302 Found 到 dl.boxcloud.com 的 URL。客户端需要遵循重定向才能实际下载文件。除非文件 ID 无效或用户无权访问,否则返回文件的原始数据。

我在 POSTMAN 中的回复是“200,OK” dl.boxcloud.com 没有 302。 POSTMAN 还会预览空白缩略图。如果我对 word 文档执行相同的操作,POSTMAN 会显示文档中的下一个。我期待的是一个文件下载对话框,或者上一段中描述的 url。

注意,curl 示例代码和响应也不同于描述返回的段落:

方法

GET /files/{文件 id}/内容

示例请求

curl -L https://api.box.com/2.0/files/FILE_ID/content **强文本** -H "授权:承载ACCESS_TOKEN"

示例响应 我刚刚下载的文本文件的原始文本(所以下载成功)

【问题讨论】:

    标签: curl download box-api


    【解决方案1】:

    这里有两件事混淆了这里发生的事情:

    1. POSTMAN 跟踪 GET 请求的重定向,但不提供有关请求历史记录的信息(例如,如果我说 GET URL1 并被重定向到 GET URL2,它只会告诉我我原来的 GET URL1,即使它提供了GET URL2)的结果

    2. 文档中的 cURL 示例包含一个 -L 标志 tells cURL to follow redirect。 cURL 不以提供任何超出明确要求的信息而闻名,这是另一种情况。

    如果您想查看实际发生的情况,可以通过添加 'v 标志将 cURL 置于详细模式并查看发生的所有情况,例如:

    curl -v -L https://api.box.com/2.0/files/FILE_ID/content -H "Authorization: Bearer TOKEN"
    
    * About to connect() to api.box.com port 443 (#0)
    *   Trying 74.112.184.225...
    * connected
    * Connected to api.box.com (74.112.184.225) port 443 (#0)
    * SSLv3, TLS handshake, Client hello (1):
    * SSLv3, TLS handshake, Server hello (2):
    * SSLv3, TLS handshake, CERT (11):
    * SSLv3, TLS handshake, Server finished (14):
    * SSLv3, TLS handshake, Client key exchange (16):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSL connection using RC4-SHA
    * Server certificate:
    *    subject: serialNumber=ts5jamwzcjWP0oTyh2m74yh0zsB2zyOR; C=US; ST=California; L=Palo Alto; O=Box.net, Inc.; CN=*.box.com
    *    start date: 2011-09-27 22:07:27 GMT
    *    expire date: 2013-09-29 11:02:11 GMT
    *    subjectAltName: api.box.com matched
    *    issuer: C=US; O=GeoTrust, Inc.; CN=GeoTrust SSL CA
    *    SSL certificate verify ok.
    > GET /2.0/files/5620199214/content HTTP/1.1
    > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
    > Host: api.box.com
    > Accept: */*
    > Authorization: Bearer TOKEN
    > 
    < HTTP/1.1 302 Found
    < Server: nginx
    < Date: Sun, 17 Mar 2013 20:48:40 GMT
    < Content-Type: text/html; charset=utf-8
    < Connection: keep-alive
    < Cache-control: no-cache, no-store
    < Location: https://www.boxcloud.com/bc/1/b4c1b5e872bf843d3ded7bcae5f4f175/2Of-pgQHiFlfW6KldVyHAxtUIEW0l7HoOpi14-VGcxcSnn2CtobCO1UjJZLI58w_oCTNcPMKbUR_gn-ncDkAbw,,/f9a04d69f716d92ceebd848bb9ccded8/
    < Content-Length: 0
    < 
    * Connection #0 to host api.box.com left intact
    * Issue another request to this URL: 'https://www.boxcloud.com/bc/1/b4c1b5e872bf843d3ded7bcae5f4f175/2Of-pgQHiFlfW6KldVyHAxtUIEW0l7HoOpi14-VGcxcSnn2CtobCO1UjJZLI58w_oCTNcPMKbUR_gn-ncDkAbw,,/f9a04d69f716d92ceebd848bb9ccded8/'
    * About to connect() to www.boxcloud.com port 443 (#1)
    *   Trying 74.112.184.74...
    * connected
    * Connected to www.boxcloud.com (74.112.184.74) port 443 (#1)
    * SSLv3, TLS handshake, Client hello (1):
    * SSLv3, TLS handshake, Server hello (2):
    * SSLv3, TLS handshake, CERT (11):
    * SSLv3, TLS handshake, Server finished (14):
    * SSLv3, TLS handshake, Client key exchange (16):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSLv3, TLS change cipher, Client hello (1):
    * SSLv3, TLS handshake, Finished (20):
    * SSL connection using RC4-SHA
    * Server certificate:
    *    subject: serialNumber=o2MxwjKDoF9mEZ3YNhBMR/WISRBUXT6b; C=US; ST=California; L=Palo Alto; O=Box, Inc.; CN=*.boxcloud.com
    *    start date: 2012-02-27 00:10:39 GMT
    *    expire date: 2014-03-01 01:48:45 GMT
    *    subjectAltName: www.boxcloud.com matched
    *    issuer: C=US; O=GeoTrust, Inc.; CN=GeoTrust SSL CA
    *    SSL certificate verify ok.
    > GET /bc/1/b4c1b5e872bf843d3ded7bcae5f4f175/2Of-pgQHiFlfW6KldVyHAxtUIEW0l7HoOpi14-VGcxcSnn2CtobCO1UjJZLI58w_oCTNcPMKbUR_gn-ncDkAbw,,/f9a04d69f716d92ceebd848bb9ccded8/ HTTP/1.1
    > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
    > Host: www.boxcloud.com
    > Accept: */*
    > Authorization: Bearer TOKEN
    > 
    < HTTP/1.1 200 OK
    < Server: nginx
    < Date: Sun, 17 Mar 2013 20:48:41 GMT
    < Content-Type: image/png
    < Content-Length: 15039
    < Connection: keep-alive
    < Cache-control: private
    < Accept-Ranges: bytes
    < Content-Disposition: attachment;filename="Screenshot_1_14_13_5_33_PM.png";filename*=UTF-8''Screenshot_1_14_13_5_33_PM.png
    < X-Content-Type-Options: nosniff
    < Accept-Ranges: bytes
    < 
    ?PNG
    …
    

    【讨论】:

    • 感谢肖恩的回复。您的回答帮助我了解我需要的是能够在 POSTMAN 中跟踪重定向,显然有一个 python 插件通过代理服务器支持这一点,但配置并不简单。
    【解决方案2】:

    解决方案

    获取box.com文件的直接下载链接

    你需要为此使用 Curl

    <?php
    
    
        $token = "<accsess_token>"; 
    
    //setup the request, you can also use CURLOPT_URL
    $ch = curl_init('https://api.box.com/2.0/files/FILE_ID_HERE/content');//Enter File id
    
    // Returns the data/output as a string instead of raw data
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    //Set your auth headers
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
       'Content-Type: application/json',
       'Authorization: Bearer ' . $token
       ));
    
    // get stringified data/output. See CURLOPT_RETURNTRANSFER
    $response = curl_exec($ch);
    
    // get info about the request
    $info = curl_getinfo($ch);
    // print_r($info->getBody());
    // $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    // $header = substr($response, 0, $header_size);
    // $body = substr($response, $header_size);
    echo '<pre>'; print_r($info['redirect_url']);
    // close curl resource to free up system resources
    curl_close($ch);
    ?>
    

    【讨论】:

      猜你喜欢
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      • 1970-01-01
      • 2014-09-09
      • 2018-11-24
      • 1970-01-01
      相关资源
      最近更新 更多