从谷歌驱动器列表文件时,缩略图为空 [英] Thumbnail image is null when listing file from Google Drive
问题描述
<一个href=\"http://stackoverflow.com/questions/17674008/set-thumbnail-image-for-uploading-on-google-drive\">I设置缩略图全成
在同一个活动,我用下面的code去的文件的相关信息,并在 file.getThumbnail()显示EN codeD数据 ,你知道的。
私有静态无效printFile(硬盘服务,档案文件){
的System.out.println(标题:+ file.getTitle());
的System.out.println(getThumbnail:+ file.getThumbnail());
}
但是,在另一个活动(我用的意图转移),当我列出文件夹从谷歌驱动器,file.getThumbnail()总是空(使用方法printFile()再次)。的我不知道为什么?的
下面code是对于从指定的文件夹列表文件,它全成:
私人无效的文件列表(终传动的服务,最后弦乐folderId){
新主题(新的Runnable接口(){ @覆盖
公共无效的run(){
Files.List请求;
尝试{
请求= service.files()列表()。
//指定文件夹的设置ID
request.setQ(folderId);
做{
尝试{
文件列表的fileList = request.execute();
request.setPageToken(fileList.getNextPageToken()); //实现:获取文件列表
对于(文件文件:fileList.getItems()){
printFile(服务,文件); // TODO获取拇指指甲在这里
InputStream为=
downloadThumbnailFile(ManageFileDriveActivity.mDriveService,文件);
//我们不需要注意此方法,因为file.getThumnail()目前为空
}
}赶上(最终IOException异常五){
request.setPageToken(NULL);
}
}而(request.getPageToken()!= NULL
&功放;&安培; request.getPageToken()长()&GT; 0);
}赶上(最终IOException异常E1){
}
}
})。开始();
}
请告诉我如何获取拇指指甲形象成功。
谢谢!
更新
使用以下code,很好的解决方案:
公共静态的InputStream downloadThumbnailFile(硬盘服务,档案文件)
抛出IOException
如果(file.getThumbnailLink()=空&放大器;!&放大器;!file.getThumbnailLink()的isEmpty()){
尝试{
的System.out.println(getThumbnailLink:+ file.getThumbnailLink());
HTT presponse RESP = service.getRequestFactory()
.buildGetRequest(新GenericUrl(file.getThumbnailLink()))
。执行(); 返回resp.getContent();
}赶上(IOException异常五){
//发生错误。
e.printStackTrace();
返回null;
}
}其他{
//该文件没有存储在云端硬盘的任何内容。
返回null;
}
}
使用 file.getThumbnailLink()
。 缩略图
属性是只写的。
I set the thumbnail successfull
In the same activity, I used following code to get information related to file, and the file.getThumbnail() show encoded data, you know.
private static void printFile(Drive service, File file) {
System.out.println("Title: " + file.getTitle());
System.out.println("getThumbnail: " + file.getThumbnail());
}
But in another activity (I use intent to transfer), when I list folder from Google Drive, file.getThumbnail() always null (use method printFile() again). I don't know why? The following code is for listing files from specified folder, it successfull :
private void listFile(final Drive service, final String folderId) {
new Thread(new Runnable() {
@Override
public void run() {
Files.List request;
try {
request = service.files().list();
// Set id of the specified folder
request.setQ(folderId);
do {
try {
FileList fileList = request.execute();
request.setPageToken(fileList.getNextPageToken());
// Implement : get list of files
for (File file : fileList.getItems()) {
printFile(service, file);
// TODO Get thumb nail in here
InputStream is =
downloadThumbnailFile(ManageFileDriveActivity.mDriveService, file);
// We don't need note this method, because file.getThumnail() currently is null
}
} catch (final IOException e) {
request.setPageToken(null);
}
} while (request.getPageToken() != null
&& request.getPageToken().length() > 0);
} catch (final IOException e1) {
}
}
}).start();
}
p/s : - Get file - File resource
Please tell me how to get Thumb nail image successful. Thanks!
UPDATE Use the following code, the good solution :
public static InputStream downloadThumbnailFile(Drive service, File file)
throws IOException {
if (file.getThumbnailLink() != null && !file.getThumbnailLink().isEmpty()) {
try {
System.out.println("getThumbnailLink: " + file.getThumbnailLink());
HttpResponse resp = service.getRequestFactory()
.buildGetRequest(new GenericUrl(file.getThumbnailLink()))
.execute();
return resp.getContent();
} catch (IOException e) {
// An error occurred.
e.printStackTrace();
return null;
}
} else {
// The file doesn't have any content stored on Drive.
return null;
}
}
Use file.getThumbnailLink()
. thumbnail
attribute is write-only.
这篇关于从谷歌驱动器列表文件时,缩略图为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!