@Override public Attachment<?> createAttachment(NativeDocument document, String parentPath, String path, int totalAttachmentsCount, Boolean downloadRemoteAttachments) throws InvalidAttachmentException { Assert.notNull(path, "Path is null"); Assert.notNull(parentPath, "Parent path is null"); File workingDirectory = new File(workingDirectoryPath); Assert.isTrue(workingDirectory.isDirectory(), "WorkingDirectory is not a directory"); Assert.notNull(workingDirectory, "WorkingDirectory is null"); AttachmentFetcher fetcher = repository.getSupportedFetcher(path); final AttachmentInformation information; if (fetcher != null) { information = fetcher.getAttachmentInformation(document.getId(), path, totalAttachmentsCount); } else { information = new AttachmentInformation(null, path); } if (information.getAttachment() != null) { document.addExistingAttachment(information.getAttachment(), false); return information.getAttachment(); } else if(information.getLocation() != null){ File attachmentFile = new File(workingDirectory + File.separator + information.getLocation()); if (attachmentFile.exists()) { return addAttachment(document, attachmentFile, parentPath); } else { throw new InvalidAttachmentException(path, ""); } } return null; }