Dropbox Sharing file URL

后端 未结 3 1603
余生分开走
余生分开走 2020-12-09 12:19

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

相关标签:
3条回答
  • 2020-12-09 12:44

    I believe the url is as follows:

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

    0 讨论(0)
  • 2020-12-09 12:45

    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.

    0 讨论(0)
  • 2020-12-09 12:53

    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.

    0 讨论(0)
提交回复
热议问题