Dropbox api v2 for Android:如何获取媒体文件的详细信息?
Dropbox api v2 for Android: how to get media files details?
如何使用 Dropbox API v2 for Android(Java) 获取媒体文件及其详细信息?我已经通过 documentation 获取 FileMetadata
,但我找不到获取文件详细信息的方法,例如文件类型(例如音乐、视频、照片、文本...)、文件的 URL 和缩略图。
这是我的文件夹和文件列表 Asyntask:
//login
DbxClientV2 client = DropboxClient.getClient(accessToken);
// Get files and folder metadata from root directory
String path = "";
TreeMap<String, Metadata> children = new TreeMap<>();
try {
try {
result = client.files().listFolder(path);
arrayList = new ArrayList<>();
//arrayList.add("/");
while (true) {
int i = 0;
for (Metadata md : result.getEntries()) {
if (md instanceof DeletedMetadata) {
children.remove(md.getPathLower());
} else {
String fileOrFolder = md.getPathLower();
children.put(fileOrFolder, md);
//if (!fileOrFolder.contains("."))//is a file
arrayList.add(fileOrFolder);
if (md instanceof FileMetadata) {
FileMetadata file = (FileMetadata) md;
//I need something like file.mineType, file.url, file.thumbnail
file.getParentSharedFolderId();
file.getName();
file.getPathLower();
file.getPathDisplay();
file.getClientModified();
file.getServerModified();
file.getSize();//in bytes
MediaInfo mInfo = file.getMediaInfo();//Additional information if the file is a photo or video, null if not present
MediaInfo.Tag tag;
if (mInfo != null) {
tag = mInfo.tag();}
}
}
i++;
}
if (!result.getHasMore()) break;
try {
result = client.files().listFolderContinue(result.getCursor());//what is this for ?
} catch (ListFolderContinueErrorException ex) {
ex.printStackTrace();
}
}
} catch (ListFolderErrorException ex) {
ex.printStackTrace();
}
} catch (DbxException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
如果您需要媒体信息,您应该使用listFolderBuilder
to get a ListFolderBuilder
object. You can use call .withIncludeMediaInfo(true)
to set the parameter for media information, and then .start()
进行API 调用。结果将包含媒体信息集(如果可用)。
Dropbox API v2 不提供 MIME 类型,但您可以根据需要保留自己的文件扩展名到 MIME 类型映射。
要获取文件的现有 link,请使用 listSharedLinks
. To create a new one, use createSharedLinkWithSettings
。
要获取文件的缩略图,请使用 getThumbnail
。
如何使用 Dropbox API v2 for Android(Java) 获取媒体文件及其详细信息?我已经通过 documentation 获取 FileMetadata
,但我找不到获取文件详细信息的方法,例如文件类型(例如音乐、视频、照片、文本...)、文件的 URL 和缩略图。
这是我的文件夹和文件列表 Asyntask:
//login
DbxClientV2 client = DropboxClient.getClient(accessToken);
// Get files and folder metadata from root directory
String path = "";
TreeMap<String, Metadata> children = new TreeMap<>();
try {
try {
result = client.files().listFolder(path);
arrayList = new ArrayList<>();
//arrayList.add("/");
while (true) {
int i = 0;
for (Metadata md : result.getEntries()) {
if (md instanceof DeletedMetadata) {
children.remove(md.getPathLower());
} else {
String fileOrFolder = md.getPathLower();
children.put(fileOrFolder, md);
//if (!fileOrFolder.contains("."))//is a file
arrayList.add(fileOrFolder);
if (md instanceof FileMetadata) {
FileMetadata file = (FileMetadata) md;
//I need something like file.mineType, file.url, file.thumbnail
file.getParentSharedFolderId();
file.getName();
file.getPathLower();
file.getPathDisplay();
file.getClientModified();
file.getServerModified();
file.getSize();//in bytes
MediaInfo mInfo = file.getMediaInfo();//Additional information if the file is a photo or video, null if not present
MediaInfo.Tag tag;
if (mInfo != null) {
tag = mInfo.tag();}
}
}
i++;
}
if (!result.getHasMore()) break;
try {
result = client.files().listFolderContinue(result.getCursor());//what is this for ?
} catch (ListFolderContinueErrorException ex) {
ex.printStackTrace();
}
}
} catch (ListFolderErrorException ex) {
ex.printStackTrace();
}
} catch (DbxException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
如果您需要媒体信息,您应该使用listFolderBuilder
to get a ListFolderBuilder
object. You can use call .withIncludeMediaInfo(true)
to set the parameter for media information, and then .start()
进行API 调用。结果将包含媒体信息集(如果可用)。
Dropbox API v2 不提供 MIME 类型,但您可以根据需要保留自己的文件扩展名到 MIME 类型映射。
要获取文件的现有 link,请使用 listSharedLinks
. To create a new one, use createSharedLinkWithSettings
。
要获取文件的缩略图,请使用 getThumbnail
。