2015-03-31 95 views
1

我将文档上传到Google云端硬盘已成功,但我的元数据似乎没有正确回复我。Google Drive API,元数据

protected File insertFile(Drive service, List<String> parentIds, com.google.drive.FileContent fileContent, File googleFile)throws IOException { 
    // Set the parent folder. 
    if (parentIds != null && parentIds.size() > 0) { 
     List<ParentReference> parentReferences = new ArrayList<ParentReference>(); 
     for (String parentId : parentIds){ 
      parentReferences.add(new ParentReference().setId(parentId)); 
     } 
     googleFile.setParents(parentReferences); 
    } 

    try { 

     googleFile = service.files().insert(googleFile, fileContent).execute(); 

     // Uncomment the following line to print the File ID. 
     System.out.println("File ID: " + googleFile.getId()); 

     return googleFile; 
    } 
    catch (IOException e) { 
     System.out.println("An error occured: " + e); 
     return null; 
    } 
} 

上面是我的insert语句,下面是我发送的有关文档的详细信息。

{描述= XXXXXXX发票,fileExtension = PDF, indexableText = {文本= XXXXXXX发票},标签= {受限= FALSE}, mime类型=应用/ PDF,父母= [{ID = 0B_owsnWRsIy7S1VsWG1vNTYzM1k }], 属性= [{键= DocumentType,值= 11}],标题= XXXXXXX发票}

当我使用此代码

protected InputStream downloadFile(Drive service, File file)throws IOException { 
    if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) { 

     HttpResponse resp = 
      service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl())) 
       .execute(); 
     return resp.getContent(); 
    } 
    else { 
     // The file doesn't have any content stored on Drive. 
     return null; 
    } 
} 
该相同文档做一个get

我将大部分文本减去可索引的文本和文件扩展名,是否正确(不想显示,因为它包含很多噪声信息)?

回答

2

这里有两个单独的问题。

1)fileExtension是一个只读字段,因此它被忽略。检索信息时,它来自原始标题/文件名。由于您的标题不包含“.pdf”,因此它被设置为空。

2)indexableText是只写的,我们不允许您在设置之后检索它;它仅被驱动器后端用于服务搜索查询。

您可以阅读关于file resource in our documentation的不同元数据属性的更多信息。