【发布时间】:2015-04-01 04:24:58
【问题描述】:
我已成功将文档上传到 Google 云端硬盘,但我的元数据似乎没有正确返回给我。
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;
}
}
上面是我的插入语句,下面是我作为文档详细信息发送的内容。
{description=XXXXXXX 发票,fileExtension=pdf, indexableText={text=XXXXXXX 发票},标签={restricted=false}, mimeType=应用程序/pdf,父母=[{id=0B_owsnWRsIy7S1VsWG1vNTYzM1k}], properties=[{key=DocumentType, value=11}], title=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;
}
}
我得到了大部分文本减去可索引的文本和文件扩展名,是否正确(不想显示,因为它包含很多噪音信息)?
【问题讨论】:
标签: google-drive-api