We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
bryancart32
9 years agoExplorer | Level 3
Help downloading a non-image file using the API
I am trying to use the v2 API to to get a temporary link to a file. JPG files work fine, but I have some .dcm files. These are medical image DICOM format files. I need to be able to create a tempo...
Greg-DB
Dropbox Community Moderator
9 years agoHi Bryan, to clarify, are you calling /2/files/get_temporary_link with that parameter? That shouldn't produce an error like that. Please share the full request and response (just be sure to redact the access token) so we can take a look. Thanks!
- bryancart329 years agoExplorer | Level 3
Thank you for your reply.
When I log into dropbox, this is the URL for the file preview:
https://www.dropbox.com/home/DICOM/13c76bf2914c6d87786d555f0994c531?preview=1.dcm
Here is the call I am making to the API:
URL: https://api.dropboxapi.com/2/files/get_temporary_link
Auth: Bearer TOKEN
JSON Post:
{"path":"/DICOM/13c76bf2914c6d87786d555f0994c531/1.dcm"}
Response:
Invalid URL: https://api.dropboxapi.com/2/files/get_temporary_link
I think that's it. Your help is greatly appreciated.
Bryan
- Greg-DB9 years ago
Dropbox Community Moderator
Thanks Bryan. That is the correct URL for this API endpoint, and that doesn't seem to be the actual API request/response though.
For example, using curl, this works for me: (just using a made up 1.dcm file in my test account)
$ curl -vX POST https://api.dropboxapi.com/2/files/get_temporary_link \ > --header "Authorization: Bearer <ACCESS_TOKEN>" \ > --header "Content-Type: application/json" \ > --data "{\"path\":\"/DICOM/13c76bf2914c6d87786d555f0994c531/1.dcm\"}" > POST /2/files/get_temporary_link HTTP/1.1 > User-Agent: curl/7.33.0 > Host: api.dropboxapi.com > Accept: */* > Authorization: Bearer <ACCESS_TOKEN> > Content-Type: application/json > Content-Length: 56 > } [data not shown] * upload completely sent off: 56 out of 56 bytes < HTTP/1.1 200 OK * Server nginx is not blacklisted < Server: nginx < Date: Thu, 27 Jul 2017 23:19:17 GMT < Content-Type: application/json < Transfer-Encoding: chunked < Connection: keep-alive < Vary: Accept-Encoding < Vary: Accept-Encoding < Cache-Control: no-cache < Pragma: no-cache < X-Content-Type-Options: nosniff < X-Dropbox-Http-Protocol: None < X-Dropbox-Request-Id: 388c65354c4b571dbcc5ce3e25d736f0 < X-Frame-Options: SAMEORIGIN < X-Server-Response-Time: 315 < { [data not shown] 100 811 0 755 100 56 835 61 --:--:-- --:--:-- --:--:-- 940 * Connection #0 to host api.dropboxapi.com left intact { "metadata": { "name": "1.dcm", "path_lower": "/dicom/13c76bf2914c6d87786d555f0994c531/1.dcm", "path_display": "/DICOM/13c76bf2914c6d87786d555f0994c531/1.dcm", "id": "id:25N5ksooX-sAAAAAAAMc8Q", "client_modified": "2017-07-27T21:46:04Z", "server_modified": "2017-07-27T21:46:05Z", "rev": "71d18021eccc7", "size": 9, "content_hash": "824979ede959fefe53082bc14502f8bf041d53997ffb65cbbe3ade5803f7fb76" }, "link": "https://dl.dropboxusercontent.com/apitl/1/AACh0gTVcnX-KmJkXbSH5qALdmLo1QoLJyQHbpVRXKVYBbn2ZFaJsIXdAXr1JM0sTg7RiQPaeymbJmyeSpkDaA505w_9tl_W6rGoXFr90T-1eMy9A3KGzfhnTORWSFbRi9JTPFJInNZepU2rZp6EzuLbjC64SXHpeVnT2F35auCpVQjDepr3hjxBudK1tF2uLmcpk5LhylRJGOpcCZrlT0hJlowU0huvfaUCqX-6ZgAiVsPDuuOVGSs-bOfNaj-LvnImgmkkG_e0fxusqFjpVu6MH0roCfouL3QQI60Izt8cFg" }What are you using to make the call? Can you share a screenshot showing it? Thanks in advance!
- bryancart329 years agoExplorer | Level 3
I used PHP and fopen. This is my function:
function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array('method' => 'POST','content' => $data)); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } echo "<pre>";print_r($params);echo "</pre>"; $ctx = stream_context_create($params); try { $fp = @fopen($url, 'rb', false, $ctx); } catch(Exception $ex) { echo '1 Error: ' .$ex->getMessage(); } //if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } if (!$fp) { echo "2 Error: ".$php_errormsg; } $response = @stream_get_contents($fp); echo "<pre>";print_r($response);echo "</pre>"; if ($response === false) { $response = "Invalid URL: ".$url;/*echo "Problem reading data from $url.";*/ } return $response; }
THIS ONE WORKED DOWNLOADING A JPG FILE:Array ( [http] => Array ( [method] => POST [content] => {"path":"/DICOM/13c76bf2914c6d87786d555f0994c531/1.jpg"} [header] => Content-Type: application/json Authorization: Bearer [TOKEN-HERE] ) )
RETURNED:{ "metadata":{ "name":"1.jpg", "path_lower":"/dicom/13c76bf2914c6d87786d555f0994c531/1.jpg", "path_display":"/DICOM/13c76bf2914c6d87786d555f0994c531/1.jpg", "id":"id:PnjeM0FAI_AAAAAAAAAJWQ", "client_modified":"2017-07-07T14:26:41Z", "server_modified":"2017-07-07T14:26:41Z", "rev":"13004a8335bf", "size":982513, "content_hash":"3a3179223b1b08759a3b5d222d1a7d226b16557b3f98b75d88874bce27d74bb2" }, "link":"https://dl.dropboxusercontent.com/apitl/1/AACiQGW0Md8EYbPrqqNkdPsl ..." }
THIS ONE FAILED DOWNLOADING A DCM FILE:Array ( [http] => Array ( [method] => POST [content] => {"path":"/DICOM/13c76bf2914c6d87786d555f0994c531/1.dcm"} [header] => Content-Type: application/json Authorization: Bearer [TOKEN-HERE] ) )
I do not know how to get any more details of why the response failed.
Any other ideas?
About Dropbox API Support & Feedback
Find help with the Dropbox API from 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!