到目前爲止,我已經成功地將Dropbox API與我的項目集成在一起。爲此,我一直在使用Dropbox SDK中給出的示例程序。從我可以下載的方式(隨機圖片)和輕鬆上傳文件。我的問題是,我們如何從Dropbox帳戶一次下載一個文件夾或多個文件? 。此外,當我點擊下載按鈕,它隨機選擇一個圖像文件,然後顯示,而不是這樣做,我想下載所有圖像文件或特定的文件夾。任何建議或幫助,將不勝感激。從android的下拉框中下載多個文件或文件夾?
在此先感謝。
到目前爲止,我已經成功地將Dropbox API與我的項目集成在一起。爲此,我一直在使用Dropbox SDK中給出的示例程序。從我可以下載的方式(隨機圖片)和輕鬆上傳文件。我的問題是,我們如何從Dropbox帳戶一次下載一個文件夾或多個文件? 。此外,當我點擊下載按鈕,它隨機選擇一個圖像文件,然後顯示,而不是這樣做,我想下載所有圖像文件或特定的文件夾。任何建議或幫助,將不勝感激。從android的下拉框中下載多個文件或文件夾?
在此先感謝。
嗨,請通過下面的代碼,這可能對你有幫助。
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
。
如果您需要從下拉框中獲取所有文件和文件夾,只需將此代碼複製並粘貼到項目中並查看結果即可。它會幫助你很多。
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
for (Entry ent: dirent.contents)
{
String name = ent.fileName();
System.out.println("My File in Folder "+name);
}
可能重複檢索的所有文件和文件夾: http://stackoverflow.com/questions/6180926/android- dropbox-api-file-download –