1

これまでのところ、Dropbox API をプロジェクトにうまく統合できました。そのために、Dropbox SDK で提供されているサンプル プログラムを使用してきました。ファイルを簡単にダウンロード(ランダム画像)してアップロードできる方法から。私の質問は、Dropbox アカウントからフォルダーまたは複数のファイルを一度にダウンロードするにはどうすればよいですか? . さらに、ダウンロード ボタンをクリックすると、ランダムに 1 つの画像ファイルが選択されて表示されます。これを行う代わりに、すべての画像ファイルまたは特定のフォルダーをダウンロードします。提案や助けをいただければ幸いです。

前もって感謝します。

4

3 に答える 3

1

ドロップ ボックスからすべての FILES と FOLDER を取得する必要がある場合は、このコードをコピーしてプロジェクトに貼り付け、結果を確認してください。それはあなたを大いに助けます。

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

//ループを実行し、PATH からすべての FILES と FOLDER を取得します

     for (Entry ent: dirent.contents)
     {
       String name = ent.fileName();                           
       System.out.println("My File in Folder "+name);                        
      }  
于 2014-04-13T14:27:57.480 に答える
1

こんにちは、次のコードを実行してください。これが役立つ場合があります。

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

于 2013-08-19T11:57:06.297 に答える
0

Sync API は、ファイルを開いたときにオンデマンドでファイルをダウンロードすることによって機能します。したがって、読み込もうとしているすべてのファイルを開くだけです。

于 2013-08-19T11:53:17.493 に答える