Tony
Tony

Reputation: 3805

How to download file using dropbox

I'm trying to build an app that gives my users right to download file from my dropbox storage.

So I've got next quesions:

1) I was following the dropbox tutorial and it says:

If the Dropbox app is installed, the SDK will switch to it so the user doesn't have to sign in, and it will fallback to the browser if not.

If I run my app, it will open a browser with dropbox web site. Is there any way to avoid that?

2) Is it possible to download file by file name only? Can I just set url for my storage and file name without randomized url?

Upvotes: 2

Views: 2270

Answers (2)

Maksim Kovalev
Maksim Kovalev

Reputation: 398

You can simply use client to download file by name

    DbxEntry.File md;
    File file = new File("destination.file");
    OutputStream out = new FileOutputStream(file);
    try {
        md = client.getFile("/path/to/target.file", null, out);
    } finally {
        out.close();
    }

Here null indicates that you want to receive the latest revision of file. And "/path/to/target.file" is path to file on your dropbox, like "/Public/001.jpg".

Also md can be used to retrieve some metadata about this file, like its size, name, revision, etc.

Upvotes: 0

alexandre1985
alexandre1985

Reputation: 1106

You can use the dropbox public folder for downloading the file that you want. You just have to put the file in that folder and then copy the url.
Then on you java you just have to put the code to download from a URL.
This is how I have done in my program and it doesn't open any browser. A good thing about the URL in Public folder, is that it doesn't change if the filename doesn't change, so you can update your file and the URL will be the same

Upvotes: 2

Related Questions