开发者

Dropbox Sharing file URL

I am developing an application for Android and which uses Dropbox for organizing the files. I am exploring the Dropbox API but its description and help is limited, as there is no documentation for the Dropbox API.

I still would like to manage the files to some functionality, for example placing a file and getting a file from Dropbox. Now the problem is when I put some fil开发者_高级运维es in Dropbox public folder and I need a URL to share to my contacts in the application. But in the API I could not find any function that returns the web URL of the file to share (Just like in the Deskotop interface of Dropbox, a user can get a Shared URL to send to friends).

Could someone help me figure out how to share that file with contacts in the Application?

Or any other way to share a file using Dropbox Android API?


According to changes made on DropBox metioned here: https://www.dropbox.com/help/16/en There would be no more Public folders, instead access to files can be done via Share Link.

If you use Android DropBox Core Api then shared link can be retrieved this way:

// Get the metadata for a directory
Entry dirent = mApi.metadata(mPath, 1000, null, true, null);

for (Entry ent : dirent.contents) {

String shareAddress = null;
if (!ent.isDir) {
    DropboxLink shareLink = mApi.share(ent.path);
    shareAddress = getShareURL(shareLink.url).replaceFirst("https://www", "https://dl");
    Log.d(TAG, "dropbox share link " + shareAddress);
}   
}

UPDATE: 2014/07/20 by Dheeraj Bhaskar Use the following helper function alongwith the above function. Since DropBox started to send shortened links it is little bit more problematic to get proper link. For now, I am using this method :

We simply load the URL, follow the redirects and get the new URL.

    String getShareURL(String strURL) {
    URLConnection conn = null;
    String redirectedUrl = null;
    try {
        URL inputURL = new URL(strURL);
        conn = inputURL.openConnection();
        conn.connect();

        InputStream is = conn.getInputStream();
        System.out.println("Redirected URL: " + conn.getURL());
        redirectedUrl = conn.getURL().toString();
        is.close();

    } catch (MalformedURLException e) {
        Log.d(TAG, "Please input a valid URL");
    } catch (IOException ioe) {
        Log.d(TAG, "Can not connect to the URL");
    }

    return redirectedUrl;
}

Note: All of this should be done of course in AsyncTask or Thread. This will produce proper links ready to download

Update 2014/07/25: Change in dropbox share URLs
A heads-up on the kind of URLs to expect
From the Dropbox team:

We wanted to give you a heads up about an upcoming change to the URL structure of Dropbox shared links. While not part of the API, the change could affect apps that manipulate the URLs returned from the /shares endpoint or the "preview" link type returned by the Chooser Drop-in.

Links returned will now have a ?dl=0 appended to them.

E.g., instead of https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx, you'll receive URLs like this link https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx?dl=0.


A useful thread in the Dropbox forums:

http://forums.dropbox.com/topic.php?id=37700&replies=7#post-326432

IF The public link for a file is always

dl.dropbox.com/u/<your users uid>/<path under /Public>/filename

then we can just use the API to get and build the public URL in the code.

Perhaps this may also help: Upload a file to Dropbox and copy public address. This script upload a file to your /Public directory and use your accound UID to build it's public URL. Then, it echoes the URL to the console.

https://github.com/sylvainfilteau/dropbox-api-command/commit/6aa817c79220c5de4ff5339cd01ea8b528bcac36

I am not there yet in my Dropbox interface implementation, but this is one of the functions I need to develop. More in one or two days I hope.


I believe the url is as follows:

http://dl.dropbox.com/u/YOUR_DROPBOX_ID/YOUR_FILE_NAME

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜