4

有谁知道如何获取元数据列表...我的意思是存在于我们的应用程序文件夹中的文件和文件夹在 Android 的 Dropbox 中。我需要获取文件和文件夹名称..现在我想再次从 android.i 在 Dropbox 中创建文件夹reffered dropbox docs.but 没有找到相同的.. 提前谢谢。

4

4 回答 4

3

这是我所做的,对我来说效果很好。

SavedProperties.selectedAddress是我的static变量,其中包含要创建的文件夹的名称。

我在这里

1)检查文件夹是否存在。

2)如果不存在则创建文件夹。

3)将文件上传到该文件夹​​。

    private void loadMetadata() 
    {


        // Metadata
        try 
        {
            Entry existingEntry = mApi.metadata("/" + SavedProperties.selectedAddress , 1, null, false, null);
            if(existingEntry.isDir)
            {
                Log.d(TAG, "Folder exists : " + existingEntry.fileName());
                uploadPictures("/"+SavedProperties.selectedAddress + "/");
            }
        } 
        catch (DropboxException  e) 
        {
            Log.d(TAG,"Folder does not exist..." + e.fillInStackTrace());
            try 
            {
                Entry createFolder = mApi.createFolder("/"+SavedProperties.selectedAddress);
                Log.d(TAG,"Folder created..." + createFolder.rev);
                uploadPictures("/"+SavedProperties.selectedAddress + "/");
            } 
            catch (DropboxException e1)
            {
                 Log.d(TAG,"Create Folder DropboxException : " + e1.fillInStackTrace() );
            }       
        }
    }

    private void uploadPictures(String uploadTo) 
    {
        // Uploading Pictures....
        FileInputStream inputStream = null;
        try 
        {
            for(int i =0 ; i < selectedImages.length; i++)
            {
                if(selectedImages[i]==0)
                {
                    String path = PictureGallery.images.get(i).toString().replace("file://", "");
                    String filename = PictureGallery.images.get(i).toString().split("/")[PictureGallery.images.get(i).toString().split("/").length-1];
                    File file = new File(path);
                    inputStream = new FileInputStream(file);
                    Entry newEntry = mApi.putFile(uploadTo + filename, inputStream, file.length(), null, null);
                    Log.i(TAG, "The uploaded file's rev is: " + newEntry.rev);
                    //Log.d(TAG,"PictureGallery " + PictureGallery.images.get(i).toString().split("/")[PictureGallery.images.get(i).toString().split("/").length-1]);
                }
            }
            progress.dismiss();
        } catch (DropboxUnlinkedException e) {
            // User has unlinked, ask them to link again here.
            Log.e(TAG, "User has unlinked.");
        } catch (DropboxException e) {
            Log.e(TAG, "Something went wrong while uploading.");
        } catch (FileNotFoundException e) {
            Log.e(TAG, "File not found.");
        } 
        finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {}
            }
        }
    }

在我的情况下,我使用了 android sdk 1.3.1。

于 2012-06-07T12:57:04.487 回答
2

我有同样的问题,并找出来。访问完成后,如上所述创建一个新条目,但将参数“布尔列表”设置为 true。如果你这样做了,List 不会为空,你可以通过 for 循环获取你想要的信息

AccessTokenPair access = getStoredKeys();
mDBApi.getSession().setAccessTokenPair(access);

try {
    // ----SET boolean list PARAMETER TO TRUE---------

    Entry dropboxDir = mDBApi.metadata("/YOUR_FOLDER_NAME/", 0, null, true, null);
    if (dropboxDir.isDir) {
        List<Entry> contents = dropboxDir.contents;
        if (contents != null) {
            // ------CREATE NEW ENTRY AND THEN, GET THE FILENAME OF
            // EVERY FILE
            for (int i = 0; i < contents.size(); i++) {
                Entry e = contents.get(i);
                String a = e.fileName();
                Log.d("dropbox", "FileName:" + a);
            }
        }
    }
    // ONLY A TEST CATCH, PLEASE DO WRIGHT EXCEPTION HANDLING HERE
} catch (Exception ex) {
    Log.d("dropbox", "ERROR");
}
于 2012-09-02T09:30:52.180 回答
0
Entry entries = mApi.metadata(Path, 100, null, true, null);

for (Entry e : entries.contents) {
    if (!e.isDeleted) {
        Log.i("Is Folder",String.valueOf(e.isDir));
        Log.i("Item Name",e.fileName());
    }
}
于 2013-09-03T06:08:41.883 回答
0

如果您想从路径中检索所有文件和文件夹,请使用此代码,它将帮助您。

我自己得到了解决方案。

    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);                        
      }  
于 2014-04-13T14:22:13.977 回答