11

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 files 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?

phwd
  • 19,975
  • 5
  • 50
  • 78
Ijaz Ahmed
  • 2,330
  • 4
  • 19
  • 27
  • 1
    I found some documentation: https://www.dropbox.com/developers/docs Were you referring to something else? – knpwrs Apr 23 '11 at 17:16
  • @KPthunder.. thanks for your reply...i have seen this documentation already there is not method mentioned for sharing thats is my question. thanks – Ijaz Ahmed Apr 27 '11 at 09:05

3 Answers3

13

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.

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
MP23
  • 1,763
  • 20
  • 25
  • 1
    Updated getShareURL Function. Your method was crashing the app with `NullPointerException`because there was no header field called Location anymore. – Dheeraj Bhaskar Jul 20 '14 at 06:57
  • getShareUrl gives null, and DropBox generate this kind of link https://db.tt/icnETNj1j . Can you please suggest me how to solve shared link issues – Satyaki Mukherjee Dec 05 '16 at 10:06
2

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.

Giulio Prisco
  • 941
  • 9
  • 16
  • THank you so much for you answer, i will check and then say something on it. i didnt get your last comment, what do you mean by " More in one or two days I hope".. the function is developed for sharing or you still developing? Thanks – Ijaz Ahmed Jun 12 '11 at 10:25
  • I am developing a tool to upload any file to the user public folder on Dropbox and post the link to Facebook or similar sites with a standard text header, I will post the code here when done. – Giulio Prisco Jun 12 '11 at 13:45
  • can i use the dropbox public url as a source in HTML5: – bouncingHippo Aug 22 '12 at 21:11
1

I believe the url is as follows:

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

Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • Thank you so much for you reply. Thanks alot..., i have a pdf file with name "Getting Started" in my Dropbox root.. and i tried this url http://dl.dropbox.com/u/mydropboxid/Getting Started .and its not working , and what is 'u' in the URL? 'U' is before YOUR_DROPBOX_ID... thank you so much for your reply. thanks – Ijaz Ahmed Apr 25 '11 at 09:31
  • @Ijaz I just noticed your comment. I believe that's because of the space. Try http://dl.dropbox.com/u/yourId/Getting%20Started . I have no idea why the 'u', but it's there. – Aleadam May 28 '11 at 20:02