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 agoThanks! That's helpful. So, the "Invalid URL" error isn't coming from the API itself, but rather just from this line of code:
if ($response === false) { $response = "Invalid URL: ".$url;/*echo "Problem reading data from $url.";*/ }
That will occur if `$response` is false, and `$response` will be false based on `@stream_get_contents($fp)`. The `$fp` comes from `fopen`, which will return false if an error occurs.
So, if something went wrong with the API call itself, `fopen` would return false, which wouldn't be a valid `resource` as `stream_get_contents` expects, so `stream_get_contents` would then return false, and trigger your `$response === false` line.
According to the fopen documentation: "If the open fails, an error of level E_WARNING is generated.". I can't offer much general PHP advice, but it looks like there is some information in this StackOverflow post about getting the error information, if that's where the issue is occuring.
It looks like you already have some other `echo` statements in the case where things failed though. Are you getting any output from those?
Alternatively, you can use curl in PHP instead, like shown in this example.
bryancart32
9 years agoExplorer | Level 3
I finally was able to find that the error I am getting back from DropBox is this:
fopen(https://api.dropboxapi.com/2/files/get_temporary_link): failed to open stream: HTTP request failed! HTTP/1.1 409 Conflict
I did some searching and I was not able to see why this is happening. Any ideas?
Thanks!
Bryan
- Greg-DB9 years ago
Dropbox Community Moderator
Thanks! That "HTTP/1.1 409 Conflict" is part of the API response, but it's only the status line. Can you print out the rest? The response body should contain a specific error.- bryancart329 years agoExplorer | Level 3
409 - Conflict
{"error_summary": "path/not_found/..", "error": {".tag": "path", "path": {".tag": "not_found"}}}When I look in the folder: /DICOM/13c76bf2914c6d87786d555f0994c531
I have 4 files: 1.jpg, 1.dcm, 2.jpg, 2.dcm
The exact same code works for 1.jpg and 2.jpg, but fails for 1.dcm and 2.dcm.
- Greg-DB9 years ago
Dropbox Community Moderator
Thanks! That is the response we're looking for.
The /2/files/get_temporary_link documentation covers what the 'not_found' error means. In this case, it does mean there was nothing found at the path supplied in the 'path' parameter.
How are you checking that the folder does contain 1.dcm and 2.dcm? Be careful checking via a computer, for example, in case your folder isn't syncing (e.g., maybe your desktop client isn't running) or in case it's linked to a different account.
You can use /2/files/list_folder to list the contents of the folder, and /2/users/get_current_account to check the linked account.
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!