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

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

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

File.setMimeType介绍

[英]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: google/data-transfer-project

private String importSingleFolder(
  UUID jobId,
  Drive driveInterface,
  String folderName,
  String folderId,
  String parentId) throws IOException {
 File newFolder = new File()
   .setName(folderName)
   .setMimeType(DriveExporter.FOLDER_MIME_TYPE);
 if (!Strings.isNullOrEmpty(parentId)) {
  newFolder.setParents(ImmutableList.of(parentId));
 }
 File resultFolder = driveInterface.files().create(newFolder).execute();
 DriveFolderMapping mapping = new DriveFolderMapping(folderId, resultFolder.getId());
 jobStore.update(jobId, folderId, mapping);
 return resultFolder.getId();
}

代码示例来源: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: google/data-transfer-project

private void importSingleFile(
  UUID jobId,
  Drive driveInterface,
  DigitalDocumentWrapper file,
  String parentId)
  throws IOException {
 InputStreamContent content = new InputStreamContent(
   null,
   jobStore.getStream(jobId, file.getCachedContentId()));
 DtpDigitalDocument dtpDigitalDocument = file.getDtpDigitalDocument();
 File driveFile = new File().setName(dtpDigitalDocument.getName());
 if (!Strings.isNullOrEmpty(parentId)) {
  driveFile.setParents(ImmutableList.of(parentId));
 }
 if (!Strings.isNullOrEmpty(dtpDigitalDocument.getDateModified())) {
  driveFile.setModifiedTime(DateTime.parseRfc3339(dtpDigitalDocument.getDateModified()));
 }
 if (!Strings.isNullOrEmpty(file.getOriginalEncodingFormat())
   && file.getOriginalEncodingFormat().startsWith("application/vnd.google-apps.")) {
  driveFile.setMimeType(file.getOriginalEncodingFormat());
 }
 driveInterface.files().create(
   driveFile,
   content
 ).execute();
}

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

private FileList createFileList(java.util.List<String> fileIds, String folderId) {
  FileList fileList = new FileList();
  java.util.List<File> list = Lists.newArrayList();
  for (String fileId : fileIds) {
   File f = new File();
   f.setId(fileId);
   f.setModifiedTime(new DateTime(System.currentTimeMillis()));
   list.add(f);
  }

  if (folderId != null) {
   File f = new File();
   f.setMimeType(FOLDER_MIME_TYPE);
   f.setId(folderId);
   f.setModifiedTime(new DateTime(System.currentTimeMillis()));
   list.add(f);
  }
  fileList.setFiles(list);
  return fileList;
 }
}

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

private File getFolder(final String name) {
  final File result = GoogleUtil.getFile(name);
  result.setMimeType(DriveOverview.MIME_TYPE_FOLDER);
  return result;
}

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

public static File getFolder(final String name) {
  final File result = getFile(name);
  result.setMimeType(DriveOverview.MIME_TYPE_FOLDER);
  return result;
}

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

public static File getSpreadsheetFile(final String name, final String id) {
  final File result = getFile(name, id);
  result.setMimeType(DriveOverview.MIME_TYPE_GOOGLE_SPREADSHEET);
  return result;
}

代码示例来源:origin: andresoviedo/google-drive-ftp-adapter

private File mkdir_impl(GFile gFile, int retry) {
  try {
    // New file
    logger.info("Creating new directory...");
    File file = new File();
    file.setMimeType("application/vnd.google-apps.folder");
    file.setName(gFile.getName());
    file.setModifiedTime(new DateTime(System.currentTimeMillis()));
    file.setParents(new ArrayList<>(gFile.getParents()));
    file = drive.files().create(file).setFields(REQUEST_FILE_FIELDS).execute();
    logger.info("Directory created successfully: " + file.getId());
    return file;
  } catch (IOException e) {
    if (retry > 0) {
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e1) {
        throw new RuntimeException(e1);
      }
      logger.warn("Uploading file failed. Retrying... '" + gFile.getId());
      return mkdir_impl(gFile, --retry);
    }
    throw new RuntimeException("Exception uploading file " + gFile.getId(), e);
  }
}

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

public void store(SyncDirectory syncDirectory) {
  Drive drive = driveFactory.getDrive(this.credential);
  try {
    java.io.File localFile = syncDirectory.getLocalFile().get();
    File remoteFile = new File();
    remoteFile.setName(localFile.getName());
    remoteFile.setMimeType(MIME_TYPE_FOLDER);
    remoteFile.setParents(createParentReferenceList(syncDirectory));
    BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class);
    remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis()));
    LOGGER.log(Level.FINE, "Inserting new directory '" + syncDirectory.getPath() + "'.");
    if (!options.isDryRun()) {
      File insertedFile = executeWithRetry(options, () -> drive.files().create(remoteFile).execute());
      syncDirectory.setRemoteFile(Optional.of(insertedFile));
    }
  } catch (IOException e) {
    throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e);
  }
}

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

public File createDirectory(File parentDirectory, String title) {
  File returnValue = null;
  Drive drive = driveFactory.getDrive(this.credential);
  try {
    File remoteFile = new File();
    remoteFile.setName(title);
    remoteFile.setMimeType(MIME_TYPE_FOLDER);
    remoteFile.setParents(Arrays.asList(parentDirectory.getId()));
    LOGGER.log(Level.FINE, "Creating new directory '" + title + "'.");
    if (!options.isDryRun()) {
      returnValue = executeWithRetry(options, () -> drive.files().create(remoteFile).execute());
    }
  } catch (IOException e) {
    throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to create directory: " + e.getMessage(), e);
  }
  return returnValue;
}

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

private File createSpreadsheet(final String name, final java.io.File export, final String mime) throws IOException {
  final FileContent fc = new FileContent(mime, export);
  final File parent = getOrCreateRoboZonkyFolder(); // retrieve Google folder in which to place the spreadsheet
  // convert the spreadsheet to Google Spreadsheet
  final File f = new File();
  f.setName(name);
  f.setParents(Collections.singletonList(parent.getId()));
  f.setMimeType(MIME_TYPE_GOOGLE_SPREADSHEET);
  LOGGER.debug("Creating a new Google spreadsheet: {}.", f);
  final File result = driveService.files().create(f, fc)
      .setFields(getFields())
      .execute();
  // and mark the time when the file was last updated
  LOGGER.debug("New Google spreadsheet created: {}.", result.getId());
  return result;
}

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

/**
 * Create a folder in the specified parent folder
 *
 * @param parentFolderId folder ID where to create folderName
 * @param folderName new folder's name
 * @return folder ID value
 * @throws IOException when operation fails
 */
public String createFolder(String parentFolderId, String folderName) throws IOException {
  File createdFolder = new File();
  createdFolder.setName(folderName);
  createdFolder.setMimeType(MIME_TYPE_FOLDER);
  createdFolder.setParents(Collections.singletonList(parentFolderId));
  return drive.files().create(createdFolder).setFields("id").execute().getId();
}

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

private File createSpreadsheet(final String name, final java.io.File export, final String mime) throws IOException {
  final FileContent fc = new FileContent(mime, export);
  final File parent = getOrCreateRoboZonkyFolder(); // retrieve Google folder in which to place the spreadsheet
  // convert the spreadsheet to Google Spreadsheet
  final File f = new File();
  f.setName(name);
  f.setParents(Collections.singletonList(parent.getId()));
  f.setMimeType(MIME_TYPE_GOOGLE_SPREADSHEET);
  LOGGER.debug("Creating a new Google spreadsheet: {}.", f);
  final File result = driveService.files().create(f, fc)
      .setFields(getFields())
      .execute();
  // and mark the time when the file was last updated
  LOGGER.debug("New Google spreadsheet created: {}.", result.getId());
  return result;
}

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

/**
 * Create a folder in the specified parent folder
 *
 * @param parentFolderId folder ID where to create folderName
 * @param folderName new folder's name
 * @return folder ID value
 * @throws IOException when operation fails
 */
public String createFolder(String parentFolderId, String folderName) throws IOException {
  File createdFolder = new File();
  createdFolder.setName(folderName);
  createdFolder.setMimeType(MIME_TYPE_FOLDER);
  createdFolder.setParents(Collections.singletonList(parentFolderId));
  return drive.files().create(createdFolder).setFields("id").execute().getId();
}

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

private File createRoboZonkyFolder(final Drive driveService) throws IOException {
  final File fileMetadata = new File();
  fileMetadata.setName(getFolderName(sessionInfo));
  fileMetadata.setDescription("RoboZonky aktualizuje obsah tohoto adresáře jednou denně brzy ráno.");
  fileMetadata.setMimeType(MIME_TYPE_FOLDER);
  final File result = driveService.files().create(fileMetadata)
      .setFields(getFields())
      .execute();
  LOGGER.debug("Created a new Google folder '{}'.", result.getId());
  return result;
}

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

private File createRoboZonkyFolder(final Drive driveService) throws IOException {
  final File fileMetadata = new File();
  fileMetadata.setName(getFolderName(sessionInfo));
  fileMetadata.setDescription("RoboZonky aktualizuje obsah tohoto adresáře jednou denně brzy ráno.");
  fileMetadata.setMimeType(MIME_TYPE_FOLDER);
  final File result = driveService.files().create(fileMetadata)
      .setFields(getFields())
      .execute();
  LOGGER.debug("Created a new Google folder '{}'.", result.getId());
  return result;
}

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

public static File getFile(final String name, final String id) {
  final File result = new File();
  result.setId(id);
  result.setMimeType("application/vnd.google-apps.files");
  result.setName(name);
  result.setModifiedTime(new DateTime(System.currentTimeMillis()));
  return result;
}

代码示例来源:origin: iterate-ch/cyberduck

@Override
public Path touch(final Path file, final TransferStatus status) throws BackgroundException {
  try {
    final Drive.Files.Create insert = session.getClient().files().create(new File()
      .setName(file.getName())
      .setMimeType(status.getMime())
      .setParents(Collections.singletonList(fileid.getFileid(file.getParent(), new DisabledListProgressListener()))));
    final File execute = insert.setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
    return new Path(file.getParent(), file.getName(), file.getType(),
      new DriveAttributesFinderFeature(session, fileid).toAttributes(execute));
  }
  catch(IOException e) {
    throw new DriveExceptionMappingService().map("Cannot create file {0}", e, file);
  }
}

代码示例来源:origin: iterate-ch/cyberduck

properties.setMimeType(status.getMime());
session.getClient().files().update(id, properties).
  setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();

代码示例来源:origin: iterate-ch/cyberduck

@Override
public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException {
  try {
    if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(folder.getParent())) {
      final TeamDrive execute = session.getClient().teamdrives().create(
        new UUIDRandomStringService().random(), new TeamDrive().setName(folder.getName())
      ).execute();
      return new Path(folder.getParent(), folder.getName(), folder.getType(),
        new PathAttributes(folder.attributes()).withVersionId(execute.getId()));
    }
    else {
      // Identified by the special folder MIME type application/vnd.google-apps.folder
      final Drive.Files.Create insert = session.getClient().files().create(new File()
        .setName(folder.getName())
        .setMimeType("application/vnd.google-apps.folder")
        .setParents(Collections.singletonList(fileid.getFileid(folder.getParent(), new DisabledListProgressListener()))));
      final File execute = insert
        .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
      return new Path(folder.getParent(), folder.getName(), folder.getType(),
        new DriveAttributesFinderFeature(session, fileid).toAttributes(execute));
    }
  }
  catch(IOException e) {
    throw new DriveExceptionMappingService().map("Cannot create folder {0}", e, folder);
  }
}

相关文章