关于 Google 云端硬盘,在此 Document ,Google 表示有 3 种 uploadType
:
我们有media
、multipart
和resumable
,如上图所示。
此外,在提到的同一文档中,Google 给出了一个 Java 示例,解释了如何将文件上传到 Google Drive。
public class MyClass {
private static File insertFile(Drive service, String title, String description,
String parentId, String mimeType, String filename) {
// File's metadata.
File body = new File();
body.setTitle(title);
body.setDescription(description);
body.setMimeType(mimeType);
// Set the parent folder.
if (parentId != null && parentId.length() > 0) {
body.setParents(
Arrays.asList(new ParentReference().setId(parentId)));
}
// File's content.
java.io.File fileContent = new java.io.File(filename);
FileContent mediaContent = new FileContent(mimeType, fileContent);
try {
File file = service.files().insert(body, mediaContent).execute();
// Uncomment the following line to print the File ID.
// System.out.println("File ID: " + file.getId());
return file;
} catch (IOException e) {
System.out.println("An error occured: " + e);
return null;
}
}
// ...
}
我想设置一个可选查询参数
,如图所示。我找不到如何在 Google Drive 的 java SDK 中设置 ocr
和 ocrLanguage
。上面的上传示例,没有设置这个参数,也不清楚这个java示例使用什么uploadType
来上传。
您可以使用通用设置属性方法
File body = new File();
body.setTitle(title);
body.set("ocr",true);
body.set("ocrLanguage", "zh");
我是一名优秀的程序员,十分优秀!