Reputation: 1837
Dropbox now have an apsolutely new API, which is absolutely differ from the old one (it's interesting why), but there's no ANY actual examples in the internet, so I've found only some code in their examples. Here is it:
// Download the file.
try (OutputStream outputStream = new FileOutputStream (file)) {
mDbxClient.files ()
.download (metadata.getPathLower (), metadata.getRev ())
.download (outputStream);
}
I need to download file from remote folder to the local one, so I need to use this path for example:
.download ("Backups/backup.ab", "/storage/sdcard/Folder/backup.ab")
I've tried it, but get a error
IllegalArgumentException: String 'rev' does not match pattern'
Do you know, what it can be, and metadata.getPathLower ()
and metadata.getRev ()
methods are using for? I've learned, that metadata
var gets from the first argv from execute (), but what this functions do?
Thanks a lot!
Upvotes: 1
Views: 7093
Reputation: 734
Not sure if if works for android. I have posted the following method just in case someone is looking for a C# .net solution.
private async Task Download(DropboxClient dbx, string folder, string file, string localFilePath)
{
using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
{
using (var fileStream = File.Create(localFilePath))
{
(await response.GetContentAsStreamAsync()).CopyTo(fileStream);
}
}
}
Parameter example:
file = "YourFileName.pdf";
folder = "/YourDropboxFolderName";
localFilePath = @"C:\Users\YourUserName\YourFileName.pdf";
Upvotes: 3
Reputation: 16930
The Dropbox API v2 Java SDK's download
method takes these two parameters:
String path
String rev
Per the download
method documentation there, the first is the remote path of the file in Dropbox you want to download, and the second is the identifier for the revision of the file you want. The second parameter is not the local path where you want to save the file, as it appears you're supplying in your code. Instead, you save the file content using the .download (outputStream);
portion of the sample code you posted, e.g., as also shown in this sample code.
Also, as stated in the documentation, the second parameter is deprecated and should no longer be used. You can just use the version of the download
method that only takes the one parameter. The code for using it is otherwise the same as the sample.
For reference, in the sample, the metadata
object is an instance of FileMetadata
. You can find more information on the getPathLower
and getRev
methods in the documentation as well.
Upvotes: 1