com.google.api.services.drive.Drive.getRequestFactory()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中com.google.api.services.drive.Drive.getRequestFactory()方法的一些代码示例,展示了Drive.getRequestFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drive.getRequestFactory()方法的具体详情如下:
包路径:com.google.api.services.drive.Drive
类名称:Drive
方法名:getRequestFactory

Drive.getRequestFactory介绍

暂无

代码示例

代码示例来源:origin: siom79/jdrivesync

private HttpResponse executeSessionInitiationRequest(Drive drive, File remoteFile) throws IOException {
  GenericUrl url = new GenericUrl("https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable");
  JsonHttpContent metadataContent = new JsonHttpContent(drive.getJsonFactory(), remoteFile);
  HttpRequest httpRequest = drive.getRequestFactory().buildPostRequest(url, metadataContent);
  LOGGER.log(Level.FINE, "Executing session initiation request to URL " + url);
  return httpRequest.execute();
}

代码示例来源:origin: lime-ime/limeime

private static InputStream downloadFile(Drive service, com.google.api.services.drive.model.File file) {
  if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
    try {
      HttpResponse resp =
          service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
              .execute();
      return resp.getContent();
    } catch (IOException e) {
      // An error occurred.
      e.printStackTrace();
      return null;
    }
  } else {
    // The file doesn't have any content stored on Drive.
    return null;
  }
}

代码示例来源:origin: siom79/jdrivesync

public InputStream downloadFile(SyncItem syncItem) {
  Drive drive = driveFactory.getDrive(this.credential);
  try {
    File remoteFile = syncItem.getRemoteFile().get();
    GenericUrl genericUrl = null;
    if(isGoogleAppsDocumentforExport(remoteFile)){
      Optional<String> exportMimeType = supportedGooglMimeType.get(remoteFile.getMimeType());
      Export export = drive.files().export(remoteFile.getId(), exportMimeType.get());
      genericUrl = export.buildHttpRequestUrl();
    }else{
      genericUrl = drive.files().get(remoteFile.getId()).set("alt", "media").buildHttpRequestUrl();
    }
    if (genericUrl != null) {
      HttpRequest httpRequest = drive.getRequestFactory().buildGetRequest(genericUrl);
      LOGGER.log(Level.FINE, "Downloading file " + remoteFile.getId() + ".");
      if (!options.isDryRun()) {
        HttpResponse httpResponse = executeWithRetry(options, () -> httpRequest.execute());
        return httpResponse.getContent();
      }
    } else {
      LOGGER.log(Level.SEVERE, "No download URL for file " + remoteFile);
    }
  } catch (Exception e) {
    throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to download file: " + e.getMessage(), e);
  }
  return new ByteArrayInputStream(new byte[0]);
}

代码示例来源:origin: siom79/jdrivesync

int resume = 0;
while (currentChunkEnd <= fileEnd) {
  HttpRequest putRequest = drive.getRequestFactory().buildPutRequest(putUrl, new ChunkedHttpContent(localFile, determineMimeType(localFile), currentChunkStart, currentChunkEnd));
  if (resume == 0) {
    long contentLength = currentChunkEnd - currentChunkStart + 1;
    putRequest = drive.getRequestFactory().buildPutRequest(putUrl, new EmptyContent());
    long contentLength = 0;
    putRequest.getHeaders().setContentLength(contentLength);

代码示例来源:origin: siom79/jdrivesync

LOGGER.log(Level.FINE, "Session initiation request returned upload location: " + location);
GenericUrl putUrl = new GenericUrl(location);
HttpRequest putRequest = drive.getRequestFactory().buildPutRequest(putUrl, fileContent);
LOGGER.log(Level.FINE, "Executing upload request to URL " + putUrl);
HttpResponse putResponse = putRequest.execute();

代码示例来源:origin: siom79/jdrivesync

public void upload(Drive drive, final File fileToUpload, String mimeType, com.google.api.services.drive.model.File remoteFile) throws IOException {
  HttpRequestFactory requestFactory = drive.getRequestFactory();
  String uploadLocation = executeWithRetry(options, () -> requestUploadLocation(fileToUpload, mimeType, requestFactory, remoteFile));
  GenericUrl uploadUrl = new GenericUrl(uploadLocation);

相关文章