简体   繁体   中英

Google Drive Upload with Optional Query Parameters - OCR

About Google Drive, in this Document , Google says there are 3 types of uploadType : 谷歌证据

We have the media , multipart and resumable , as it says in the image above.

Also, in the same Document mentioned, Google give a example on Java, explaining how to upload an File into 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;
}
}

  // ...
}

I want to set an Optional Query Parameter , as explained in the image. I can't find how to set the ocr and ocrLanguage in the java SDK of Google Drive. The example of upload above, don't have this parameter to set, also, is not clear what uploadType this java example uses to Upload.

You can use generic set property method

File body = new File(); 
body.setTitle(title);
body.set("ocr",true);
body.set("ocrLanguage", "zh");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM