我正在成功上传文件到谷歌驱动器,但我的元数据似乎没有得到正确的回我。
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语句,下面是我发送的关于该文档的详细信息。
{description=XXXXXXX发票,fileExtension=pdf,indexableText={text=XXXXXXX发票},labels={restricted=false},mimeType=application/pdf,parents={id=0B_owsnWRsIy7S1VsWG1vNTYzM1k},properties={key=DocumentType,value=11},title=XXXXXXX发票}
当我使用以下代码为同一个文档做get时
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;
}
}我得到的大部分文本减去可索引的文本和文件扩展名,这是正确的(不想显示,因为它包含了大量的信息是噪音)?
发布于 2015-03-31 20:24:58
这里有两个独立的问题.
1) fileExtension是一个只读字段,因此被忽略。检索信息时,它是从原始标题/文件名派生出来的。因为您的标题不包括".pdf“,所以它被设置为空。
2) indexableText是只写的,我们不允许您在设置之后检索它;它仅由驱动器后端用于服务搜索查询。
您可以更多地了解文档中的文件资源的不同元数据属性。
https://stackoverflow.com/questions/29377568
复制相似问题