2015-03-31 42 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的不同元數據屬性的更多信息。