com.google.api.services.drive.model.File.getMimeType()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(87)

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

File.getMimeType介绍

[英]The MIME type of the file. Drive will attempt to automatically detect an appropriate value from uploaded content if no value is provided. The value cannot be changed unless a new revision is uploaded. If a file is created with a Google Doc MIME type, the uploaded content will be imported if possible. The supported import formats are published in the About resource.
[中]文件的MIME类型。如果没有提供值,驱动器将尝试从上传的内容中自动检测适当的值。除非上载新版本,否则无法更改该值。如果文件是使用Google Doc MIME类型创建的,则上传的内容将在可能的情况下导入。支持的导入格式发布在“关于”资源中。

代码示例

代码示例来源:origin: apache/incubator-gobblin

private FileStatus toFileStatus(File metadata) {
 return new FileStatus(metadata.getSize() == null ? 0L : metadata.getSize(),
            FOLDER_MIME_TYPE.equals(metadata.getMimeType()),
            -1,
            -1,
            metadata.getModifiedTime().getValue(),
            new Path(metadata.getId()));
}

代码示例来源:origin: google/data-transfer-project

if (FOLDER_MIME_TYPE.equals(file.getMimeType())) {
 folders.add(new BlobbyStorageContainerResource(file.getName(), file.getId(), null, null));
} else if (FUSION_TABLE_MIME_TYPE.equals(file.getMimeType())) {
 monitor.info(() -> "Exporting of fusion tables is not yet supported: " + file);
} else if (MAP_MIME_TYPE.equals(file.getMimeType())) {
 monitor.info(() -> "Exporting of maps is not yet supported: " + file);
} else {
 try {
  InputStream inputStream;
  String newMimeType = file.getMimeType();
  if (EXPORT_FORMATS.containsKey(file.getMimeType())) {
   newMimeType = EXPORT_FORMATS.get(file.getMimeType());
   inputStream =
     driveInterface
      new DtpDigitalDocument(
        file.getName(), file.getModifiedTime().toStringRfc3339(), newMimeType),
      file.getMimeType(),
      file.getId()));
 } catch (Exception e) {

代码示例来源:origin: pentaho/pentaho-kettle

protected void doCreateFolder() throws Exception {
 if ( !getName().getBaseName().isEmpty() ) {
  File folder = new File();
  folder.setName( getName().getBaseName() );
  folder.setMimeType( MIME_TYPES.FOLDER.mimeType );
  folder = driveService.files().create( folder ).execute();
  if ( folder != null ) {
   id = folder.getId();
   mimeType = MIME_TYPES.get( folder.getMimeType() );
  }
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

private void resolveFileMetadata() throws Exception {
 String parentId = null;
 if ( getName().getParent() != null ) {
  File parent = searchFile( getName().getParent().getBaseName(), null );
  if ( parent != null ) {
   FileType mime = MIME_TYPES.get( parent.getMimeType() );
   if ( mime.equals( FileType.FOLDER ) ) {
    parentId = parent.getId();
   }
  }
 }
 String fileName = getName().getBaseName();
 File file = searchFile( fileName, parentId );
 if ( file != null ) {
  mimeType = MIME_TYPES.get( file.getMimeType() );
  id = file.getId();
 } else {
  if ( getName().getURI().equals( GoogleDriveFileProvider.SCHEME + ":///" ) ) {
   mimeType = FileType.FOLDER;
  }
 }
}

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

public boolean isDirectory(File file) {
  if (MIME_TYPE_FOLDER.equals(file.getMimeType())) {
    return true;
  }
  return false;
}

代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky

private static Stream<File> listSpreadsheets(final Stream<File> all) {
  return all.filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_GOOGLE_SPREADSHEET));
}

代码示例来源:origin: RoboZonky/robozonky

private static Stream<File> listSpreadsheets(final Stream<File> all) {
  return all.filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_GOOGLE_SPREADSHEET));
}

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

public boolean isGoogleAppsDocument(File file) {
  String mimeType = file.getMimeType();
  if (mimeType != null && mimeType.startsWith("application/vnd.google-apps") && !mimeType.equals("application/vnd.google-apps.folder")) {
    LOGGER.log(Level.FINE, "Not touching file " + file.getId() + " because it is a Google Apps document.");
    return true;
  }
  return false;
}

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

public boolean isGoogleAppsDocumentforExport(File file) {
  String mimeType = file.getMimeType();
  if (mimeType != null && supportedGooglMimeType.containsKey(mimeType)) {
    LOGGER.log(Level.FINE, "exporting file " + file.getId() + " because it is a Google Apps document.");
    return true;
  }
  return false;
}

代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky

public static DriveOverview create(final SessionInfo sessionInfo, final Drive driveService,
                  final Sheets sheetService) throws IOException {
  final String folderName = getFolderName(sessionInfo);
  LOGGER.debug("Listing all files in the root of Google Drive, looking up folder: {}.", folderName);
  final List<File> files = getFilesInFolder(driveService, "root").collect(Collectors.toList());
  final Optional<File> result = files.stream()
      .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()))
      .filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_FOLDER))
      .filter(f -> Objects.equals(f.getName(), folderName))
      .findFirst();
  if (result.isPresent()) {
    return create(sessionInfo, driveService, sheetService, result.get());
  } else {
    return new DriveOverview(sessionInfo, driveService, sheetService);
  }
}

代码示例来源:origin: RoboZonky/robozonky

public static DriveOverview create(final SessionInfo sessionInfo, final Drive driveService,
                  final Sheets sheetService) throws IOException {
  final String folderName = getFolderName(sessionInfo);
  LOGGER.debug("Listing all files in the root of Google Drive, looking up folder: {}.", folderName);
  final List<File> files = getFilesInFolder(driveService, "root").collect(Collectors.toList());
  final Optional<File> result = files.stream()
      .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()))
      .filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_FOLDER))
      .filter(f -> Objects.equals(f.getName(), folderName))
      .findFirst();
  if (result.isPresent()) {
    return create(sessionInfo, driveService, sheetService, result.get());
  } else {
    return new DriveOverview(sessionInfo, driveService, sheetService);
  }
}

代码示例来源:origin: org.apache.gobblin/google-ingestion

private FileStatus toFileStatus(File metadata) {
 return new FileStatus(metadata.getSize() == null ? 0L : metadata.getSize(),
            FOLDER_MIME_TYPE.equals(metadata.getMimeType()),
            -1,
            -1,
            metadata.getModifiedTime().getValue(),
            new Path(metadata.getId()));
}

代码示例来源:origin: com.github.robozonky/robozonky-integration-stonky

private static Stream<File> getFilesInFolder(final Drive driveService, final String parentId) throws IOException {
  LOGGER.debug("Listing files in folder {}.", parentId);
  return driveService.files().list()
      .setQ("'" + parentId + "' in parents and trashed = false")
      .setFields("nextPageToken, files(" + getFields("mimeType") + ")")
      .execute()
      .getFiles()
      .stream()
      .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()));
}

代码示例来源:origin: RoboZonky/robozonky

private static Stream<File> getFilesInFolder(final Drive driveService, final String parentId) throws IOException {
  LOGGER.debug("Listing files in folder {}.", parentId);
  return driveService.files().list()
      .setQ("'" + parentId + "' in parents and trashed = false")
      .setFields("nextPageToken, files(" + getFields("mimeType") + ")")
      .execute()
      .getFiles()
      .stream()
      .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId()));
}

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

public List<File> listChildren(String parentId) {
  List<File> resultList = new LinkedList<File>();
  Drive drive = driveFactory.getDrive(this.credential);
  try {
    Drive.Files.List request = drive.files().list().setFields("nextPageToken, files");
    request.setQ("trashed = false and '" + parentId + "' in parents");
    request.setPageSize(1000);
    LOGGER.log(Level.FINE, "Listing children of folder " + parentId + ".");
    do {
      FileList fileList = executeWithRetry(options, () -> request.execute());
      List<File> items = fileList.getFiles();
      resultList.addAll(items);
      request.setPageToken(fileList.getNextPageToken());
    } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    if (LOGGER.isLoggable(Level.FINE)) {
      for (File file : resultList) {
        LOGGER.log(Level.FINE, "Child of " + parentId + ": " + file.getId() + ";" + file.getName() + ";" + file.getMimeType());
      }
    }
    removeDuplicates(resultList);
    return resultList;
  } catch (IOException e) {
    throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to execute list request: " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.talend.components/components-googledrive-runtime

/**
 * @param sourceFolderId source folder ID
 * @param destinationFolderId folder ID where to copy the sourceFolderId's content
 * @param newName folder name to assign
 * @return created folder ID
 * @throws IOException when operation fails
 */
public String copyFolder(String sourceFolderId, String destinationFolderId, String newName) throws IOException {
  LOG.debug("[copyFolder] sourceFolderId: {}; destinationFolderId: {}; newName: {}", sourceFolderId, destinationFolderId,
      newName);
  // create a new folder
  String newFolderId = createFolder(destinationFolderId, newName);
  // Make a recursive copy of all files/folders inside the source folder
  String query = format(Q_IN_PARENTS, sourceFolderId) + Q_AND + Q_NOT_TRASHED;
  FileList originals = drive.files().list().setQ(query).execute();
  LOG.debug("[copyFolder] Searching for copy {}", query);
  for (File file : originals.getFiles()) {
    if (file.getMimeType().equals(MIME_TYPE_FOLDER)) {
      copyFolder(file.getId(), newFolderId, file.getName());
    } else {
      copyFile(file.getId(), newFolderId, file.getName(), false);
    }
  }
  return newFolderId;
}

代码示例来源: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: andresoviedo/google-drive-ftp-adapter

private GFile create(File file) {
  GFile newFile = new GFile(file.getName() != null ? file.getName() : file.getOriginalFilename());
  newFile.setId(file.getId());
  newFile.setLastModified(file.getModifiedTime() != null ? file.getModifiedTime().getValue() : 0);
  newFile.setDirectory(GFile.MIME_TYPE.GOOGLE_FOLDER.getValue().equals(file.getMimeType()));
  newFile.setSize(file.getSize() != null ? file.getSize() : 0); // null for directories
  newFile.setMimeType(file.getMimeType());
  newFile.setMd5Checksum(file.getMd5Checksum());
  if (file.getParents() != null) {
    Set<String> newParents = new HashSet<>();
    for (String newParent : file.getParents()) {
      newParents.add(newParent.equals(ROOT_FOLDER_ID) ? "root" : newParent);
    }
    newFile.setParents(newParents);
  } else {
    // does this happen?
    newFile.setParents(Collections.singleton("root"));
  }
  newFile.setTrashed(file.getTrashed() != null && file.getTrashed());
  return newFile;
}

代码示例来源:origin: org.talend.components/components-googledrive-runtime

private IndexedRecord convertSearchResultToIndexedRecord(File file) {
  // Main record
  IndexedRecord main = new GenericData.Record(schema);
  main.put(0, file.getId());
  main.put(1, file.getName());
  main.put(2, file.getMimeType());
  main.put(3, file.getModifiedTime().getValue());
  main.put(4, file.getSize());
  main.put(5, file.getKind());
  main.put(6, file.getTrashed());
  main.put(7, file.getParents().toString()); // TODO This should be a List<String>
  main.put(8, file.getWebViewLink());
  return main;
}

代码示例来源:origin: Talend/components

private IndexedRecord convertSearchResultToIndexedRecord(File file) {
  // Main record
  IndexedRecord main = new GenericData.Record(schema);
  main.put(0, file.getId());
  main.put(1, file.getName());
  main.put(2, file.getMimeType());
  main.put(3, file.getModifiedTime().getValue());
  main.put(4, file.getSize());
  main.put(5, file.getKind());
  main.put(6, file.getTrashed());
  main.put(7, file.getParents().toString()); // TODO This should be a List<String>
  main.put(8, file.getWebViewLink());
  return main;
}

相关文章