Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public Publisher<PutResult> put(Path filePath, OutputStream outputStream) {
- Optional<File> optionalFile = find(filePath);
- if (optionalFile.isPresent()) {
- updateFile(optionalFile.get());
- log.info(FILE_OVERWRITTEN);
- return Mono.just(PutResult.OVERWRITTEN);
- }
- File folderMetaData = new File();
- folderMetaData.setName(filePath.toAbsolutePath().toString());
- folderMetaData.setMimeType(FILE_MIME_TYPE);
- Optional<byte[]> data = Optional.empty();
- try {
- data = Optional.of(Files.readAllBytes(filePath));
- } catch (IOException e) {
- e.printStackTrace();
- }
- InputStreamContent fileContent = null;
- if (data.isPresent()) {
- fileContent = new InputStreamContent(StringUtils.EMPTY, new ByteArrayInputStream(data.get()));
- }
- log.info(String.format(UPLOAD_START, filePath.toAbsolutePath().toString()));
- try {
- drive.files()
- .create(folderMetaData, fileContent)
- .execute();
- } catch (IOException e) {
- e.printStackTrace();
- }
- log.info(String.format(UPLOAD_DONE, filePath.toAbsolutePath().toString()));
- return Mono.just(PutResult.SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement