我將文檔上傳到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
我將大部分文本減去可索引的文本和文件擴展名,是否正確(不想顯示,因爲它包含很多噪聲信息)?