File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId();
/** * @param fileId ID of the fileName to copy * @param destinationFolderId folder ID where to copy the fileId * @param newName if not empty rename copy to this name * @param deleteOriginal remove original fileName (aka mv) * @return copied fileName ID * @throws IOException when copy fails */ public String copyFile(String fileId, String destinationFolderId, String newName, boolean deleteOriginal) throws IOException { LOG.debug("[copyFile] fileId: {}; destinationFolderId: {}, newName: {}; deleteOriginal: {}.", fileId, destinationFolderId, newName, deleteOriginal); File copy = new File(); copy.setParents(Collections.singletonList(destinationFolderId)); if (!newName.isEmpty()) { copy.setName(newName); } File resultFile = drive.files().copy(fileId, copy).setFields("id, parents").execute(); String copiedResourceId = resultFile.getId(); if (deleteOriginal) { drive.files().delete(fileId).execute(); } return copiedResourceId; }
File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId();
/** * @param fileId ID of the fileName to copy * @param destinationFolderId folder ID where to copy the fileId * @param newName if not empty rename copy to this name * @param deleteOriginal remove original fileName (aka mv) * @return copied fileName ID * @throws IOException when copy fails */ public String copyFile(String fileId, String destinationFolderId, String newName, boolean deleteOriginal) throws IOException { LOG.debug("[copyFile] fileId: {}; destinationFolderId: {}, newName: {}; deleteOriginal: {}.", fileId, destinationFolderId, newName, deleteOriginal); File copy = new File(); copy.setParents(Collections.singletonList(destinationFolderId)); if (!newName.isEmpty()) { copy.setName(newName); } File resultFile = drive.files().copy(fileId, copy).setFields("id, parents").execute(); String copiedResourceId = resultFile.getId(); if (deleteOriginal) { drive.files().delete(fileId).execute(); } return copiedResourceId; }
/** * Creates a copy of a file and applies any requested updates with patch semantics. * * Create a request for the method "files.copy". * * This request holds the parameters needed by the drive server. After setting any optional * parameters, call the {@link Copy#execute()} method to invoke the remote operation. * * @param fileId The ID of the file. * @param content the {@link com.google.api.services.drive.model.File} * @return the request */ public Copy copy(java.lang.String fileId, com.google.api.services.drive.model.File content) throws java.io.IOException { Copy result = new Copy(fileId, content); initialize(result); return result; }
public static com.google.api.services.drive.model.File copyFile(final Drive driveService, final com.google.api.services.drive.model.File upstream, final com.google.api.services.drive.model.File parent, final String name) throws IOException { LOGGER.debug("Cloning master spreadsheet '{}', setting name: {}.", upstream.getId(), name); final com.google.api.services.drive.model.File f = new com.google.api.services.drive.model.File(); f.setName(name); f.setParents(Collections.singletonList(parent.getId())); final com.google.api.services.drive.model.File result = driveService.files().copy(upstream.getId(), f) .setFields("id,name,modifiedTime") .execute(); LOGGER.debug("Created a copy: {}.", result.getId()); return result; }
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final File copy = session.getClient().files().copy(fileid.getFileid(source, new DisabledListProgressListener()), new File() .setParents(Collections.singletonList(fileid.getFileid(target.getParent(), new DisabledListProgressListener()))) .setName(target.getName())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(target.attributes()).withVersionId(copy.getId())); } catch(IOException e) { throw new DriveExceptionMappingService().map("Cannot copy {0}", e, source); } }
public static com.google.api.services.drive.model.File copyFile(final Drive driveService, final com.google.api.services.drive.model.File upstream, final com.google.api.services.drive.model.File parent, final String name) throws IOException { LOGGER.debug("Cloning master spreadsheet '{}', setting name: {}.", upstream.getId(), name); final com.google.api.services.drive.model.File f = new com.google.api.services.drive.model.File(); f.setName(name); f.setParents(Collections.singletonList(parent.getId())); final com.google.api.services.drive.model.File result = driveService.files().copy(upstream.getId(), f) .setFields("id,name,modifiedTime") .execute(); LOGGER.debug("Created a copy: {}.", result.getId()); return result; }
public String copyPresentation(String presentationId, String copyTitle) throws IOException { Drive driveService = this.driveService; // [START slides_copy_presentation] File copyMetadata = new File().setName(copyTitle); File presentationCopyFile = driveService.files().copy(presentationId, copyMetadata).execute(); String presentationCopyId = presentationCopyFile.getId(); // [END slides_copy_presentation] return presentationCopyId; }