Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

alexsajno's avatar
alexsajno
Explorer | Level 4
8 years ago

Create File object of dropbox excel file link

Hi, I have an app that have already the DbxChooser Class.

I have also this code:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == DBX_CHOOSER_REQUEST) {
if (resultCode == Activity.RESULT_OK) {

// Handle the result
DbxChooser.Result result = new DbxChooser.Result(data);
Log.d("TAG", "Link to selected file: " + result.getLink());

I can see on Logcat the full dropbox link and if I paste it on chrome I can download the file automatically. I want to download this link to a Jave File Obeject because after that I have a method thate receive "File" object (Excel file) and read the excel file. I tried to implement a DownloadFileTask but I could not make it.

How can I download the excel file from a link to a File object ?

I have also the DropboxClientFactory class ready:

package com.tkdcenter.StudentsListFromExcel;

/**
* Created by Alex on 18/9/2018.
*/

import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.http.OkHttp3Requestor;
import com.dropbox.core.v2.DbxClientV2;

public class DropboxClientFactory {

public static DbxClientV2 getClient(String ACCESS_TOKEN) {
// Create Dropbox client
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("Flashcard Maker")
.withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
.build();
DbxClientV2 client = new DbxClientV2(requestConfig, ACCESS_TOKEN);
return client;
}
}

 

4 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    Since you're getting the link from DbxChooser, you don't necessarilly need to use DbxClientV2 at all. 

    The DbxClientV2 object is for calling the full Dropbox API, but you can download directly from the Dropbox link instead.

    Exactly how you do so may depend on exactly what kind of link you requested though. 

    Either DIRECT_LINK or FILE_CONTENT may make sense in this case. 

    For DIRECT_LINK, issue an HTTPS request to the link, e.g., using HttpsURLConnection, and save the response. (Note that these links expire after four hours though, so make sure the call succeeded before saving the data.)

    For FILE_CONTENT, which should be a "file:" URL, so you should be able to open it using the File class directly. (Note that this is broken in the current version of the Dropox Android app, but will be fixed in the next version, tentatively planned for release next week.)

  • alexsajno's avatar
    alexsajno
    Explorer | Level 4
    8 years ago
    So If I choose FILE_CONTENT. I use the getPath method to get the full URL. What code I shoud use to create File object and download the excel file into it? and how I can follow when the new version is ready to use the code
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    I can't offer help with using the Android/Java File class itself unfortunately, as that's not made by Dropbox. I recommend referring to the documentation for that, or looking for Android samples or asking on a more general programming resource, e.g., StackOverflow. 

    You can see when the Dropbox Android app is updated here:

    https://play.google.com/store/apps/details?id=com.dropbox.android&hl=en

    I'll make a note to follow up on this thread when that's done though.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago

    The Dropbox Chooser now correctly returns local file links again for ResultType.FILE_CONTENT as of the latest version of the official Dropbox Android app, v114.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!