We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
anonymous
9 years agoBest way to get a file's URL
I am making an iOS app that displays all of the images from a selected folder. To make caching the images easier and more efficient I'm using the SDWebImage Library. SDWebImage requires a URL and I'm...
- 9 years agoThat is the right way to get a direct link to a file using the API.
I'll be happy to pass along as feedback or feature requests though. What specifically would be more useful? Thanks in advance!
Greg-DB
Dropbox Community Moderator
9 years agomikemalter No problem:
1. No, shared folders are not the same as shared links. There's a help center article that covers these two different kinds of sharing here:
https://help.dropbox.com/files-folders/share-file-or-folder
2. Yes, you can call the API from essentially any platform where you can make arbitrary HTTPS calls. If you're using C#, we recommend using the official Dropbox API v2 .NET SDK, if you can. The SDK will do most of the work for you. For example, it has a CreateSharedLinkWithSettingsAsync method for /2/sharing/create_shared_link_with_settings.
3. Yes, you can retrieve existing shared links using /2/sharing/list_shared_links (which is ListSharedLinksAsync in the .NET SDK).
mikemalter
9 years agoHelpful | Level 5
Hi Greg,
If I create a shared link to a folder, that does not mean that all of it's contents now have shared links. Please confirm my understanding that it's a one to one thing. Thanks.
Also, some nuances with regard to shared links. Let's say on Monday I programattically create shared links for all files and folders in our Dropbox. Then someone adds new files and folders. Can I run the same program that basically gets each item and assigns a shared link to it, or do I need to differentiate between those items who do not have a shared link and create a shared link. Will it mess anything up if I just run my shared link utility on our whole dropbox each time? I want to make sure I don't create issues on the back end for anyone.
Finally the first parameter for CreateSharedLinkWithSettingsAsync is the path of the item. So the path to an example file is "C:\Users\malter.JOYOUSLIVING\Dropbox\FoldernameLevel1\FolderNameLevel1\FileName.pdf". Is this what I pass, or do I pass the stuff just after Dropbox, or do I include Dropbox. I don't see any example code, so I'm having to wing this. Are there code examples?
Thanks.
- Greg-DB9 years ago
Dropbox Community Moderator
If you create a shared link to a folder, that link is specifically for the folder. However, that link does also enable access to the contents of that folder.
If you attempt to create a shared link for a file or folder that already has a shared link, the call will fail with an error. You can catch that error though. I illustrated that as well as the path question here in the issue you opened for the .NET SDK:
https://github.com/dropbox/dropbox-sdk-dotnet/issues/64
Hope this helps!
- mikemalter9 years agoHelpful | Level 5
Greg,
Is is possible you could post a snippet of C# code that shows how to call an async method from another class? I want to have a class called DropboxManager where I can put all of the Dropbox code in and then call those methods. But I can't figure out how to pass parameters without another level of indirection. Here are some code snippets to help you understand. This is in the Form_Load method of my Windows Form application
this.dbx = DropboxManager.GetUserToken(this.DropboxDevelopmentAccessToken); Task<FullAccount> task = Task.Run(GetCurrentAccount); task.Wait(); this.full = task.Result; this.lblDropboxUserName.Text = full.Name.DisplayName; this.lblDropboxEmailAddress.Text = full.Email; Task<List<string>> task1 = Task.Run(ListFolders); task1.Wait(); int i = task1.Result.Count;
Here are the functions that are another level of indirection and in the same class as the Form_Load method.
async Task<List<string>> ListFolders() { DropboxManager dm = new DropboxManager(); List<string> FolderList = await dm.ListFolders(dbx); return FolderList; } async Task<FullAccount> GetCurrentAccount() { try { DropboxManager dm = new DropboxManager(); return await dm.GetCurrentAccount(dbx); } catch (Exception e) { throw e; } }Here are the methods that are called in my DropboxManager class:
public async Task<List<string>> ListFolders(DropboxClient dbx) { try { List<string> FolderList = new List<string>(); var list = await dbx.Files.ListFolderAsync(string.Empty); foreach (var item in list.Entries.Where(i => i.IsFolder)) { FolderList.Add(item.Name); } return FolderList; } catch (Exception ex) { throw ex; } } public static DropboxClient GetUserToken(string oauth2AccessToken) { try { DropboxClient dbx = new DropboxClient(oauth2AccessToken); return dbx; } catch (Exception e) { throw e; } } public async Task<FullAccount> GetCurrentAccount(DropboxClient dbx) { try { return await dbx.Users.GetCurrentAccountAsync(); } catch (Exception e) { throw e; } }So you can see that the only way I can pass parameters is by executing a Run() on an async function that calls another async function. I can't figure out how to pass parameters from that first level. Is that even possible?
Thanks.
- Greg-DB9 years ago
Dropbox Community Moderator
Hi Mike, unfortunately this question sounds more like a general C# question about class and method structure and usage, which I'm afraid I can't offer help with, as it's out of scope for Dropbox API support and outside my area of expertise. Apologies I can't be of more help in that regard!
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!