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: 

Get source URL of Photo/Video - Dropbox API v2 - C#

Get source URL of Photo/Video - Dropbox API v2 - C#

SauravAnand
Explorer | Level 4
Go to solution

Hi,

 

I need to get source URL's of each photos or videos on Dropbox account.

 

Earlier with v1 is i was gettting file path like below:

var api = new DropboxApi(dropbox_appkey, dropbox_appsecret,accessToken);
var metadata = api.GetFiles("dropbox", "");

But with v2 i'm trying now:

using (var client= new DropboxClient(accessToken))
{
    var list = await client.Files.ListFolderAsync(path);
}

 With the above code i'm getting all main folders and files which are created in the Root of Dropbox, but not getting sub-folders and files of main folders/sub-folders.

 

I was trying with ListFolderContinueAsync() but stuck with parameter 'cursor' which is required.

 

Any pointers or example would be great help.

Thank you.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

To get the sub-files and folders, you'll need to set the recursive parameter. So, for example, instead of:

var list = await client.Files.ListFolderAsync(path);

you would use:

var list = await client.Files.ListFolderAsync(path, recursive:true);

The "path" you then pass in to DownloadAsync should be the "PathLower" you retrieved from the FileMetadata. (Alternatively, the "Id" would also work.) There's an example of getting the file data from the response of DownloadAsync here.

 

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

Using ListFolderAsync (and ListFolderContinueAsync) is the right way to list out files and folders in a Dropbox account via API v2 in .NET. 

 

If you want sub-folders and sub-files though, you'll need to explicitly set the recursive parameter for ListFolderAsync to true. There's more information on that in the documentation there.

 

Make sure you check the returned ListFolderResult.HasMore and call back to ListFolderContinueAsync if it's true (and so on with the result of ListFolderContinueAsync itself as well. The cursor you pass in to ListFolderContinueAsync is available in the ListFolderResult.Cursor.

 

Once you have the file metadata, you can use other method such as DownloadAsync to get the file content, or CreateSharedLinkWithSettingsAsync to create shared links. 

SauravAnand
Explorer | Level 4
Go to solution

Hi,

 

I'm using below code at the top of the method.

var list = await client.Files.ListFolderAsync(path);

Now while debug i get folder's & file's info which are in the Root of Dropbox account, but there are sub-folders too and each folders/sub-folders contains photos/videos.

 

Folders are available by "list.Entries.Where(i => i.IsFolder)" & files are by "list.Entries.Where(i => i.IsFile)".

 

After completing avove two loops i have written 'list.HasMore' condition but getting false, then how i will call ListFolderContinueAsync() to get more files.

 

I'm really confused about the parameters in both methods ListFolderAsync(string path) // what should be the path here? 

And ListFolderContinueAsync(string cursor) // what should be the cursor here? [list.Cursor] will be correct parameter?

 

My main requirement is to get source URL's of all photos/videos under Dropbox account so that later i can use DownloadAsync(string path) method to download files in my local machine. Parameter 'path' of the DownloadAsync() will be the photo/video source URL, correct?

If yes then i would like to know where i can define the destination local machine path to download to?

 

Thanks for your answer.

 

Greg-DB
Dropbox Staff
Go to solution

To get the sub-files and folders, you'll need to set the recursive parameter. So, for example, instead of:

var list = await client.Files.ListFolderAsync(path);

you would use:

var list = await client.Files.ListFolderAsync(path, recursive:true);

The "path" you then pass in to DownloadAsync should be the "PathLower" you retrieved from the FileMetadata. (Alternatively, the "Id" would also work.) There's an example of getting the file data from the response of DownloadAsync here.

 

SauravAnand
Explorer | Level 4
Go to solution
Hi Greg,

Thanks for your prompt help. I have tried and it worked as expected.
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    SauravAnand Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?