1
votes

So far I've successfully integrated Dropbox API with my project. For that I've been using an example program that is given in Dropbox SDK. From the way i can download(random Picture) and upload files easily. My question is, How can we download a folder or multiple files at a time from their dropbox account? . Additionally When i click on the download button it randomly chosen one image file then displaying, instead of doing this i want to download all image files or particular folder. Any suggestions or help would be appreciated.

Thanks in Advance.

3

3 Answers

0
votes

The Sync API works by downloading files on-demand when you open them. So just open all the files you're trying to read.

1
votes

Hi please go through following code, may be this is helpful to you.

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;
}

For more information please check the source.

1
votes

If you need to get all FILES and FOLDER from drop box, then simply copy and paste this code in your project and see the result. It will help you a lot.

    String mPath="/";  //You can change the path here to specific FOLDER
Entry dirent = null;
 try 
   {
      dirent = mApi.metadata(mPath, 1000, null, true, null);            
    } 
 catch (DropboxException e)
   {
     System.out.println("Error Detail "+e.getMessage());
   }

//Perform a Loop and retrieve all FILES and FOLDER from the PATH

     for (Entry ent: dirent.contents)
     {
       String name = ent.fileName();                           
       System.out.println("My File in Folder "+name);                        
      }