We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
ckienquoc
5 years agoExplorer | Level 4
Cannot Download File by using API
I've tried to download a file using Dropbox API & PHP with the following code:
$out_fp = fopen($local_tmp_file_path, 'w+');
$headers = array( 'Authorization: Bear...
- 5 years ago
Thanks, that's helpful. I see your client is passing up 'Content-Length: -1', which is incorrect. Mine is not doing that, so it may depend on what version of curl/PHP you're using.
Try explicitly specifying a header of: 'Content-Length: 0'.
ckienquoc
5 years agoExplorer | Level 4
This is the debug result. I've got error 400 [Bad request].
I've tried to run the same source on localhost environment and it works fine.
This code only have problem with download (Upload is OK) when I run it on Development server.
I also added the OAuth 2 Redirect Uris for both environments. One for localhost and one for https://my_website.com
Please help! Thank You
* About to connect() to content.dropboxapi.com port 443 (#2)
* Trying 162.125.82.14...
* Connected to content.dropboxapi.com (162.125.82.14) port 443 (#2)
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject: CN=content.dropboxapi.com,O="Dropbox, Inc",L=San Francisco,ST=California,C=US,serialNumber=4348296,incorporationState=Delaware,incorporationCountry=US,businessCategory=Private Organization
* start date: Jan 28 00:00:00 2021 GMT
* expire date: Feb 01 23:59:59 2022 GMT
* common name: content.dropboxapi.com
* issuer: CN=DigiCert SHA2 Extended Validation Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US
> POST /2/files/download HTTP/1.1
Host: content.dropboxapi.com
Accept: */*
Authorization: Bearer MY_TOKENXXXXXXXXXXXXXXXXXXXX
Content-Type: application/octet-stream
Dropbox-API-Arg: {"path":"\/file_data\/shared\/IMPORT_DEPARTMENT_TMP_vn.xlsx"}
Content-Length: -1
Expect: 100-continue
< HTTP/1.1 400 Bad Request
< Content-Length: 14468
< Content-Type: text/html
< Vary: Accept-Encoding
< X-Dropbox-Response-Origin: local
< Date: Fri, 09 Jul 2021 02:44:18 GMT
< Server: envoy
< Connection: close
<
* Closing connection 2
Greg-DB
Dropbox Community Moderator
5 years agoThanks, that's helpful. I see your client is passing up 'Content-Length: -1', which is incorrect. Mine is not doing that, so it may depend on what version of curl/PHP you're using.
Try explicitly specifying a header of: 'Content-Length: 0'.
- ckienquoc5 years agoExplorer | Level 4
Awesome! thank you so much ❤️
About Discuss Dropbox Developer & API
Make connections with other developers
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!