cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Best way to get a file's URL

Best way to get a file's URL

Not applicable
Go to solution

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 currently using the getTemporaryLink function to get a link for each image in the folder. Is there a better way to get a URL? I'm concerned that the links expiring will cause issues. 

24 Replies 24

mikemalter
Helpful | Level 5
Go to solution

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-DB
Dropbox Staff
Go to solution
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!

mikemalter
Helpful | Level 5
Go to solution

Greg, 

 

No issues.  I eventually got it worked out.

 

I am having an error thrown everytime I call CreateSharedLinkWithSettingsAsync.  The message says: {"Value should match pattern '\\A(?:(/(.|[\\r\\n])*|id:.*)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?))\\z'\r\nParameter name: path"} and the PathLower value is: "\\NW Region Info Table Documents\\0 Special Documents please read first file in this folder\\DropboxForSeva.docx".  I parsed out my local drive and folders and trimmed everything to the right of \\Dropbox.  What am I missing?

 

Thanks!

Greg-DB
Dropbox Staff
Go to solution
The error message is indicating that that's not a valid path value. The Dropbox path format doesn't necessarily match local filesystem path formats. For example, in this case, the path should be like "/NW Region Info Table Documents/0 Special Documents please read first file in this folder/DropboxForSeva.docx".

In general, you should just get the PathLower value from the Metadata objects returned by other API calls, such as listFolder.

mikemalter
Helpful | Level 5
Go to solution

Greg,

 

I'm trying to synch a desktop application UI with Dropbox and I started by getting a third party control that is a tree folder control.  How sure are you that Dropbox's storage is not mirrored on my machine? 

 

  1. Do you have a code sample for listFolder if all I have is a path from my computer?  Do I have enough information on my end to get metadata from Dropbox for a particular item?
  2. Do you have a code sample for getting file metadata?

Thank you.

Greg-DB
Dropbox Staff
Go to solution

If you use the official Dropbox desktop client, it will sync the contents of your Dropbox account to your local filesystem. Note that your local filesystem doesn't use the same path format as the remote Dropbox API though. For example, Dropbox API paths uses '/' as a separator, and not '\'.

1. The Dropbox API isn't really meant for use based on file paths originating from your local filesystem like this. It provides the entire file listing for your from the API itself. E.g., using listFolder as shown here:

https://github.com/dropbox/dropbox-sdk-dotnet/blob/9803a40b3169acf66a2d14e29af8750ebe6e3e17/dropbox-...

(If you need to list the root Dropbox folder, using the empty string "" as the path.)

You can technically convert a local filesystem path, though I don't have sample code for that. For instance though, you can find the local Dropbox folder using this:

https://help.dropbox.com/desktop-web/locate-dropbox-folder

Then, you can strip off the local folder root, and convert the path as necessary. (E.g., from '\" separators to "/".)

2. The listFolder method as above will return metadata, but you can also retrieve individual file metadata using GetMetadata as shown here:

https://github.com/dropbox/dropbox-sdk-dotnet/blob/9803a40b3169acf66a2d14e29af8750ebe6e3e17/dropbox-...

Pash237
New member | Level 2
Go to solution

I have exactly the same question, but I'm writing native iOS application in ObjC.

I searched, but can't find a way to get the temporary link for a file. I found mysterious `DBFILESGetTemporaryLink` and `DBFILESGetTemporaryLinkArg`, but I don't know how to use them.

 

I just need an external URL for a file in Dropbox — don't want to download it to a temporary location or data in memory.

Greg-DB
Dropbox Staff
Go to solution

@Pash237 In the Dropbox API v2 Objective-C SDK, you would use the DBFILESUserAuthRoutes -getTemporaryLink: method:

 

https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESUserAuthRoutes.html#/c:ob...:

 

That's an RPC-style method, so it would be used the same way as the createFolder example here:

 

https://github.com/dropbox/dropbox-sdk-obj-c#rpc-style-request

 

(I.e., `[[client.filesRoutes getTemporaryLink...`)

Pash237
New member | Level 2
Go to solution

Thanks, it works!

[[client.filesRoutes getTemporaryLink:path]
setResponseBlock:^(DBFILESGetTemporaryLinkResult *result, DBFILESGetTemporaryLinkError *routeError, DBRequestError *networkError) {
if (result) {
NSLog(@"Got URL for Dropbox file: %@", result.link);
}
}];

rahlpanchal
New member | Level 2
Go to solution

Can you please share the function that you have tried as I have same requirement and if you shared it would be helpful for me.

Thanks!

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    lenner90 Explorer | Level 3
  • User avatar
    iCodes Explorer | Level 3
What do Dropbox user levels mean?