简体   繁体   English

Android Dropbox API 文件下载

[英]Android Dropbox API file download

I am currently working on an android app that is to support the android dropbox api.我目前正在开发一个 android 应用程序,以支持 android 保管箱 api。 I have got it working so that it sends a file from the android sd card to a dropbox folder.我已经让它工作了,以便它将文件从 android sd 卡发送到保管箱文件夹。 I then later on need to be able to download this file and save it to the phone sd card again.然后我以后需要能够下载此文件并将其再次保存到手机的 SD 卡中。

How can I download the file from Dropbox and save it to the device, there is very little to no documentation about the android api.如何从 Dropbox 下载文件并将其保存到设备,关于 android api 的文档很少甚至没有。

Thanks for any help you can provide.感谢您的任何帮助,您可以提供。

private boolean downloadDropboxFile(String dbPath, File localFile) throws IOException{

    BufferedInputStream br = null;
    BufferedOutputStream bw = null;

    try {
        if (!localFile.exists()) {
            localFile.createNewFile(); //otherwise dropbox client will fail silently
        }

        FileDownload fd = api.getFileStream("dropbox", dbPath, null);
        br = new BufferedInputStream(fd.is);
        bw = new BufferedOutputStream(new FileOutputStream(localFile));

        byte[] buffer = new byte[4096];
        int read;
        while (true) {
        read = br.read(buffer);
        if (read <= 0) {
        break;
        }
        bw.write(buffer, 0, read);
        }
    } finally {
        //in finally block:
        if (bw != null) {
            bw.close();
        }
        if (br != null) {
            br.close();
        }
    }

    return true;
}

Source: http://forums.dropbox.com/topic.php?id=23189&replies=5#post-159521来源: http://forums.dropbox.com/topic.php?id=23189&replies=5#post-159521

if try this link, Download file from Dropbox and save it into SDCARD really help full to download the any type of file through drop box如果尝试此链接, 从 Dropbox 下载文件并将其保存到 SDCARD确实有助于通过下拉框下载任何类型的文件

private boolean downloadDropboxFile(String dbPath, File localFile) throws IOException{

    BufferedInputStream br = null;
    BufferedOutputStream bw = null;

    try {
        if (!localFile.exists()) {
            localFile.createNewFile(); //otherwise dropbox client will fail silently
        }

        FileDownload fd = api.getFileStream("dropbox", dbPath, null);
        br = new BufferedInputStream(fd.is);
        bw = new BufferedOutputStream(new FileOutputStream(localFile));

        byte[] buffer = new byte[4096];
        int read;
        while (true) {
        read = br.read(buffer);
        if (read <= 0) {
        break;
        }
        bw.write(buffer, 0, read);
        }
    } finally {
        //in finally block:
        if (bw != null) {
            bw.close();
        }
        if (br != null) {
            br.close();
        }
    }

    return true;
}

It will may be working for you.它可能对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM