@Override public boolean delete(Path path, boolean recursive) throws IOException { Preconditions.checkArgument(recursive, "Non-recursive is not supported."); String fileId = toFileId(path); LOG.debug("Deleting file: " + fileId); try { client.files().delete(fileId).execute(); } catch (GoogleJsonResponseException e) { GoogleJsonError error = e.getDetails(); if (404 == error.getCode()) { //Non-existing file id return false; } throw e; } return true; }
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(); }
File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId();
final File f = s.getOverview().latestWelcome(welcome); final Spreadsheet result = copySheet(sheetsService, s.getStonky(), f, InternalSheet.WELCOME); driveService.files().delete(f.getId()).execute(); return result; }));
final File f = s.getOverview().latestWelcome(welcome); final Spreadsheet result = copySheet(sheetsService, s.getStonky(), f, InternalSheet.WELCOME); driveService.files().delete(f.getId()).execute(); return result; }));
final String query = this.query(directory, listener); do { final FileList list = session.getClient().files().list()
File content = new File().setName(copyTitle); File presentationFile = driveService.files().copy(templatePresentationId, content).execute(); String presentationId = presentationFile.getId();
file.setName("My Image File"); FileContent mediaContent = new FileContent(imageMimeType, new java.io.File(imageFilePath)); File uploadedFile = driveService.files().create(file, mediaContent).execute(); String fileId = uploadedFile.getId(); GenericUrl getFileUrlBuilder = driveService.files().get(fileId).buildHttpRequestUrl(); String imageUrl = getFileUrlBuilder .set("access_token", credential.getAccessToken()) driveService.files().delete(fileId).execute();
if (!gFile.isExists()) { file.setParents(new ArrayList<>(gFile.getParents())); uploadRequest = drive.files().create(file, mediaContent); } else { if (gFile.getParents() == null || gFile.getParents().isEmpty()) { throw new IllegalArgumentException("Error. file parents can't be null nor empty"); uploadRequest = drive.files().update(gFile.getId(), file, mediaContent); StringBuilder parents = new StringBuilder(); gFile.getParents().forEach((p) -> parents.append(p).append(","));
FileList files = drive.files().list().setQ(query).execute(); if (files.getFiles().isEmpty()) { return Collections.emptyList();
FileList files = drive.files().list().setQ(query).execute(); if (files.getFiles().isEmpty()) { return Collections.emptyList();
.list() .setFields("files/id,files/mimeType,files/modifiedTime,files/size,files/permissions") .setPageSize(pageSize);
return drive.files().export(file.getId(), GFile.MIME_TYPE.MS_EXCEL.getValue()).executeMediaAsInputStream(); return drive.files().export(file.getId(), GFile.MIME_TYPE.MS_WORD.getValue()).executeMediaAsInputStream(); return drive.files().get(gFile.getId()).executeMediaAsInputStream(); } catch (Exception ex) { throw new RuntimeException("Error downloading file " + gFile.getId(), ex);
Files.List request = drive.files().list() .setFields("nextPageToken, files(" + REQUEST_FILE_FIELDS + ")"); request.setQ("trashed = false and '" + id + "' in parents");
properties.setName(renamed.getName()); properties.setMimeType(status.getMime()); session.getClient().files().update(id, properties). setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); final File reference = session.getClient().files().get(id) .setFields("parents") .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")) session.getClient().files().update(id, null) .setAddParents(fileid.getFileid(renamed.getParent(), new DisabledListProgressListener())) .setRemoveParents(previousParents.toString())
final File properties = new File(); properties.setTrashed(true); session.getClient().files().update(fileid.getFileid(file, new DisabledListProgressListener()), properties) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")) .queue(batch, new DeleteBatchCallback<File>(file, failures, callback)); session.getClient().files().delete(fileid.getFileid(file, new DisabledListProgressListener())) .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")) .queue(batch, new DeleteBatchCallback<Void>(file, failures, callback));
File putFile = new File(); putFile.setParents(Collections.singletonList(folderId)); Files.List fileRequest = drive.files().list() .setQ(format(QUERY_NOTTRASHED_NAME_NOTMIME_INPARENTS, parameters.getResourceName(), MIME_TYPE_FOLDER, folderId)); LOG.debug("[putResource] `{}` Exists in `{}` ? with `{}`.", parameters.getResourceName(), drive.files().delete(existingFiles.getFiles().get(0).getId()).execute(); putFile = drive.files().create(putFile, fContent).setFields(metadata).execute(); putFile = drive.files().create(putFile, content).setFields(metadata).execute();
public GoogleDriveGetResult getResource(GoogleDriveGetParameters parameters) throws IOException { String fileId = parameters.getResourceId(); File file = getMetadata(fileId, "id,mimeType,fileExtension"); String fileMimeType = file.getMimeType(); String outputFileExt = "." + file.getFileExtension(); LOG.debug("[getResource] Found fileName `{}` [id: {}, mime: {}, ext: {}]", parameters.getResourceId(), fileId, fileMimeType, file.getFileExtension()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); /* Google Apps types */ if (GoogleDriveMimeTypes.GOOGLE_DRIVE_APPS.contains(fileMimeType)) { String exportFormat = parameters.getMimeType().get(fileMimeType).getMimeType(); outputFileExt = parameters.getMimeType().get(fileMimeType).getExtension(); drive.files().export(fileId, exportFormat).executeMediaAndDownloadTo(outputStream); } else { /* Standard fileName */ drive.files().get(fileId).executeMediaAndDownloadTo(outputStream); } byte[] content = outputStream.toByteArray(); if (parameters.isStoreToLocal()) { String localFile = parameters.getOutputFileName(); if (parameters.isAddExt()) { localFile = localFile + ((localFile.endsWith(outputFileExt)) ? "" : outputFileExt); } LOG.info(messages.getMessage("message.writing.resource", parameters.getResourceId(), localFile)); try (FileOutputStream fout = new FileOutputStream(localFile)) { fout.write(content); fout.close(); } } return new GoogleDriveGetResult(fileId, content); }