2

I have to load some data to Google Drive, but I can't use recommended by Drive SDK way to do it:

FileContent fileContent = new FileContent(mimeType, dataFile);
try {
  File file = service.files().insert(body, fileContent).execute();
  return file;
} catch (IOException e) {
  System.out.println("An error occured: " + e);
  return null;
}

because my data isn't always has the java.io.File as a source. Sometimes it may be an InputStream from encrypted storage or from other cloud storage and therefore I can't get FileContent from it. Is there a way to load data from InputStream to Google Drive without their intermediate storing on file system (as for Dropbox API method "putFileOverwrite", for example)?

Community
  • 1
  • 1
isabsent
  • 3,683
  • 3
  • 25
  • 46

1 Answers1

3

Check this out

 File file= drive.files().insert(body,
                                new InputStreamContent(
                                        fileItemStream
                                                .getContentType(),
                                        new ByteArrayInputStream(
                                                IOUtils.toByteArray(fileInputStream)))).execute;
Chandan Reddy
  • 499
  • 4
  • 23