We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
pankaj_agarwal
7 years agoExplorer | Level 3
How to use the public url to access files
I am trying to create an app in c# which will download files from a given url which looks like this
This is the code I am using:
Snippet
using (var dbx = new DropboxClient("My ACCESS TOKEN HERE")) { var metadata = await dbx.Sharing.GetSharedLinkMetadataAsync(url); Console.WriteLine($"{metadata.IsFolder}, {metadata.Name}"); }
And this is the exception I get:
ApiException`1: shared_link_not_found/...
Am I doing something wrong? The above link is a publicly shared link and I was able to download the files in the browser.
Thanks for the help.
11 Replies
- Greg-DB7 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/54691106/need-help-coding-a-downloader-for-dropbox ]
The GetSharedLinkMetadataAsync method is meant for accessing the information about shared links from Dropbox itself, e.g., links like this:
https://www.dropbox.com/s/yvkdov5srlqalkd/Getting%20Started.pdf?dl=0
The link you shared is from "appspot.com", so it won't work with GetSharedLinkMetadataAsync.
If you're just trying to download a file from a publicly accessible link to the local filesystem, you don't need to use the Dropbox API; you can just use an HTTPS client.
If you want to save the linked file directly to a Dropbox account, you should instead use SaveUrlAsync.
- pankaj_agarwal7 years agoExplorer | Level 3
Can you give me some pointers on how to achieve this because with WebClient I am getting a HTML Page.
- Greg-DB7 years ago
Dropbox Community Moderator
What specifically are you trying to do, and what are you stuck on at this point?
If you're trying to downloading from appspot.com using WebClient, I can't offer help with that, as that's not related to Dropbox. (That said, what you describe does seem expected, since the link you shared is just to an HTML web page. It sounds like you probably would want to use the link to the file on that page instead.)
If you're trying to use SaveUrlAsync, or if you are trying to use GetSharedLinkMetadataAsync and switched to an actual Dropbox shared link, please shared your updated code and let me know what isn't working.
- pankaj_agarwal7 years agoExplorer | Level 3
The above link shows a folder with files in the browser. I am trying to download those files. I tried attaching the html file here but it is not working so I am pasting the code here:
<!DOCTYPE html> <html ng-app="myApp"> <head> <base href="/"> <title>Dropbox Folder</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="//static.parastorage.com/services/third-party/fonts/Helvetica/fontFace.css"> <link rel="stylesheet" href="styles/index.css"/> <script src="//static.parastorage.com/services/js-sdk/1.108.0/js/wix-private.min.js"></script> <script type="text/javascript"> var initialState = {"APP_ID":"14924864-56d5-b94b-060f-cd57bd16cc26","DEFAULT_LANGUAGE":"en","DISPLAY_MODE_FILES":"files","DISPLAY_MODE_FOLDER":"folder","LIST_FULL_WIDTH":1,"LIST_PARTIAL_WIDTH":0,"FOLDER_STYLE_OUTLINE":"outline","FOLDER_STYLE_SOLID":"solid","SIZE_SMALL":"small","SIZE_LARGE":"large","appName":"myApp","origin":"app_settings","widget_origin":"widget","appId":"14924864-56d5-b94b-060f-cd57bd16cc26","AUTH_URL":"https://www.dropbox.com/oauth2/authorize?client_id=rn9cfkc30p3l3po&response_type=token&state=testtoken&force_reapprove=false","APP_KEY":"rn9cfkc30p3l3po","REGISTER_URL":"https://www.dropbox.com/register","design":{"folder_row":{"color":"color-8","opacity":0.15},"bread_crumbs":{"color":"color-4","text":"Body-M","fontSize":12,"arrowColor":"color-4"},"number_items":{"color":"color-4","text":"Body-M","fontSize":12},"connected_cloud":{"color":"color-8","text":"Body-M"},"empty_folder_header":{"text":"Body-L","color":"color-5","fontSize":15,"fontWeight":"bold"},"empty_folder_text":{"text":"Body-M","color":"color-4","fontSize":14},"empty_folder_image":{"color":"color-8"},"icon_color":{"name":"iconColor","value":"color-8","opacity":"0.8"},"folder_icon":{"textFont":{"name":"folderIconFont","value":"Body-M","theme":"font_8"},"textColor":{"name":"folderIconColor","value":"color-8"}},"list":{"title":{"textFont":{"name":"ListTitleFont","value":"Body-L","theme":"font_7","startWithSize":20,"maxSize":42},"textColor":{"name":"ListTitleColor","value":"color-5"}},"files_names":{"textFont":{"name":"ListFilesNamesFont","value":"Body-M","theme":"font_8","maxSize":22},"textColor":{"name":"ListFilesNamesColor","value":"color-4"}},"background":{"value":"color-1","name":"listBackgroundColor","opacity":"1"},"border":{"value":"color-5","name":"listBorderColor","opacity":"0.2"},"icons":{"name":"iconsListColor","value":"color-8"}}},"data":{"settings":{"design":{"folder":{"icon_size":"small","style":"outline"},"list":{"show_numbers_of_items":1,"show_preview":1}},"lang":"en","email":{"text":"","show":1},"layout":{"type":"files"},"account":{"folderPath":"[{\"name\":\"Dropbox\",\"path_lower\":\"/\"}]","folder":"OmniScreen","email":"omnicoomniscreen@gmail.com","name":"OmniScreen Omnico","accessToken":"","fullPath":"/omniscreen","connected":1},"title":{"show":1,"text":"OmniScreen"}}}}; initialState.locationParams = document.location.search; </script> <style wix-style type="text/css" ng-non-bindable=""> .folderRow::before { background-color: {{color-8}}; opacity: 0.15; } .file-arrow #z-Stroke-2 { stroke: {{color-4}}; } .folder-path-text{ font-size: 12px !important; color: {{color-4}}; {{Body-M}}; } .items-row { font-size: 12px !important; color: {{color-4}}; {{Body-M}}; } .title { {{Body-L}}; font-size: 20px; {{style.ListTitleFont}}; color: {{style.ListTitleColor color-5}}; } .closeMe .closeMe-fill { fill: {{style.ListTitleColor color-5}}; } .folderName { {{ style.ListFilesNamesFont Body-M}} color: {{style.ListFilesNamesColor color-4}} } .extention , .fileNameNoExtention{ {{ style.ListFilesNamesFont Body-M}} color: {{style.ListFilesNamesColor color-4}} } .items { font-size: 12px !important; color: {{color-4}}; {{Body-M}}; } .ispopup { background-color: {{style.listBackgroundColor color-1}}; } .defaultBackground{ background-color: {{style.listBackgroundColor color-1}}; border : 1px solid rgba(0,0,0,0.2) ; border-color: {{style.listBorderColor}} !important; } .previewBorder{ background-color: {{style.listBackgroundColor color-1}}; } .webui-popover,.previewBorder,.full-screen-connected { border-color: {{color-5}} ; border-color: {{style.listBorderColor}} !important; } .full-screen-connected { background-color: {{color-1}}; color: {{color-5}}; } .divider , .lastDivider { background-color: {{color-5}} ; background-color: {{style.listBorderColor}}; } .mCSB_dragger_bar.inited{ background-color: {{color-5}} !important; background-color: {{style.listBorderColor}} !important; } #mCSB_2_scrollbar_vertical{ } .webui-arrow { border-top-color: {{style.listBorderColor color-5}} !important; } .arrowIcon .fill-svg, .mobileArrow .fill-svg , .home-icon path{ fill-rule: evenodd; fill : {{style.iconsListColor color-8}} !important; } .downloadFolderIcon .stroke-svg , .downloadFolderIcon path{ stroke : {{style.iconsListColor color-8}}; } .viewFileIcon .symbol-showComp path{ fill : {{style.iconsListColor color-8}}; } .closeMe .closeMe-fill { fill : {{style.iconsListColor color-8}}; } .folder-path-text:not(.selected-folder){ color : {{style.iconsListColor color-8}}; } .fileIcon .fill-svg , .folderIcon .fill-svg{ fill: {{style.iconsListColor color-8}}; } .fileIcon .stroke-svg , .folderIcon .stroke-svg { stroke: {{style.iconsListColor color-8}}; } .folderLayoutIconFill .fill-svg , .folderLayoutIconNotFill .fill-svg { fill: {{style.iconColor color-8}}; } .folderLayoutIconFill .stroke-svg, .folderLayoutIconNotFill .stroke-svg{ stroke: {{style.iconColor color-8}}; } .folderTitle{ {{style.folderIconFont Body-M}}; color : {{style.folderIconColor color-8}}; line-height: 1.4em; } .connected-cloud path { stroke: {{color-8}}; } .connected-cloud path.fill-connected { fill: {{color-8}}; } .connected-cloud--text { {{Body-M}}; } .empty-folder--header { {{Body-L}}; color: {{color-5}}; font-size: 15px; font-weight: bold; } .empty-folder--text { {{Body-M}}; color: {{color-4}}; font-size: 14px; } .empty-folder--image svg g{ fill: {{color-8}} !important; } </style> </head> <body role="application"> <div ng-view class="my-app" tabindex="-1" role="main"></div> <script src="scripts/bower-index.js"></script> <script src="scripts/scripts-index.js"></script> </body> </html>
There is a big JSON object which might be relevant as it shows links to dropbox but I am not sure how to make use of that.
Basically being able to enumerate files and folders is what I am trying to achieve in my app. This is what I tried:
private static void Fetch(string url) { using (var webClient = new WebClient()) { var uri = new Uri(url); //webClient.OpenReadCompleted += WebClient_OpenReadCompleted; //webClient.OpenReadAsync(uri); webClient.DownloadFileAsync(uri, @"D:\xyz.dat"); } } private static void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { using(StreamReader reader=new StreamReader(e.Result)) { Console.WriteLine(reader.ReadToEnd()); } }
- pankaj_agarwal7 years agoExplorer | Level 3
Any ideas?
- Greg-DB7 years ago
Dropbox Community Moderator
The Dropbox URLs in the JSON you mentioned are https://www.dropbox.com/oauth2/authorize... and https://www.dropbox.com/register, which themselves aren't directly related to downloading files. (The former is a page for authorizating an API app, and the latter is the page for registering a Dropbox account.)
The link you originally supplied is to a page on appspot.com, which is an HTML page with a file listing. That listed file also links to appspot.com, but then returns a URL on https://dl.dropboxusercontent.com/apitl/1 (which is a temporary link retrieved from the Dropbox API), resulting in a file download in the browser.
If you want the file to download to the user's machine, it appears that's already working. If that's not the behavior you want, please elaborate.
- pankaj_agarwal7 years agoExplorer | Level 3
Actually I want to check for some files periodically and download them without having to open the browser. The app will sit in the system tray and do the work.
- pankaj_agarwal7 years agoExplorer | Level 3
My question is how do I get the links to files programmatically.
- Greg-DB7 years ago
Dropbox Community Moderator
So, if I understand correctly, you want to build a client-side (presumably, Windows) application which will run on the user's computer, and will download files from a pre-existing website like that appspot page, is that correct?
Getting the links from a web site (i.e., essentially "scraping" that web site), isn't related to Dropbox itself, so I'm afraid I can't offer help with that.
Once you do get the file link (not the HTML page link), since that is just a publicly accessible link, you can download it using any HTTPS client, such as the `WebClient` you mentioned earlier.
- pankaj_agarwal7 years agoExplorer | Level 3
That's right. Its the links in the html file that I want but I am not sure how because I can't find any. That is all I want to know I can do the rest.
About Discuss Dropbox Developer & API
Make connections with other developers815 PostsLatest Activity: 22 hours ago
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 or Facebook.
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!