Dropbox和Android-通过API调用获取文件名
有人知道如何获取元数据列表吗…我指的是Android dropbox应用程序文件夹中存在的文件和文件夹。我需要获取文件和文件夹名称。。 现在我想再次从android在Dropbox中创建文件夹。我参考了Dropbox文档,但没有找到相同的。。Dropbox和Android-通过API调用获取文件名,android,dropbox-api,Android,Dropbox Api,有人知道如何获取元数据列表吗…我指的是Android dropbox应用程序文件夹中存在的文件和文件夹。我需要获取文件和文件夹名称。。 现在我想再次从android在Dropbox中创建文件夹。我参考了Dropbox文档,但没有找到相同的。。 Thanx提前通知。这里是我所做的,它对我来说很好 SavedProperties。selectedAddress是我的静态变量,其中包含要创建的文件夹的名称 我来了 1) 正在检查文件夹是否存在 2) 如果不存在,则创建文件夹 3) 将文件上载到该文件夹
Thanx提前通知。这里是我所做的,它对我来说很好
SavedProperties。selectedAddress
是我的静态
变量,其中包含要创建的文件夹的名称
我来了
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) {}
}
}
}
private void loadMetadata()
{
//元数据
尝试
{
条目existingEntry=mApi.metadata(“/”+SavedProperties.selectedAddress,1,null,false,null);
if(existingEntry.isDir)
{
Log.d(标记“文件夹存在:”+existingEntry.fileName());
上传图片(“/”+SavedProperties.selectedAddress+“/”);
}
}
捕获(DropBoxexException e)
{
Log.d(标记“文件夹不存在…”+e.fillInStackTrace());
尝试
{
条目createFolder=mApi.createFolder(“/”+SavedProperties.selectedAddress);
Log.d(标记“文件夹已创建…”+createFolder.rev);
上传图片(“/”+SavedProperties.selectedAddress+“/”);
}
捕获(DropBoxexException e1)
{
Log.d(标记“创建文件夹Dropbox异常:”+e1.fillInStackTrace());
}
}
}
私有无效上载图片(字符串上载到)
{
//正在上载图片。。。。
FileInputStream inputStream=null;
尝试
{
for(int i=0;i
在我的案例中,我使用了android sdk 1.3.1。我也遇到了同样的问题,并找到了答案。访问完成后,如上所述创建一个新条目,但 将参数“布尔列表”设置为true。若您这样做了,列表将不会为空,您可以 使用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");
}
AccessTokenPair-access=getStoredKeys();
mDBApi.getSession().setAccessTokenPair(访问);
试一试{
//----将布尔列表参数设置为TRUE---------
条目dropboxDir=mDBApi.metadata(“/YOUR_FOLDER_NAME/”,0,null,true,null);
if(dropboxDir.isDir){
列表内容=dropboxDir.contents;
如果(内容!=null){
//----创建新条目,然后获取
//每个文件
对于(int i=0;i
如果您想从path中检索所有文件和文件夹,请使用此代码,它将帮助您
我自己找到了解决办法
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());
}
//执行循环并从路径中检索所有文件和文件夹
选中此项:条目dropboxDir=mDBApi.metadata(“/”,1000,null,true,null)。。。。。。。我用它来检索所有的文件和文件夹列表,但出现异常…无法将结果传递给activityhello pratit Systemix…你应该提出一个新问题,因为这里的问题可能已经过时。从这个答案开始,大约4年过去了,dropbox api也更新了。此外,如果没有看到错误stacktrace,很难说到底是什么错误。谢谢……在这里发布了一个问题
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());
}
for (Entry ent: dirent.contents)
{
String name = ent.fileName();
System.out.println("My File in Folder "+name);
}