-1

I am trying to download a file with google drive api. The code gives no error but I can't find the file anywhere. This is the code

String fileId = "...";
  OutputStream outputStream = new ByteArrayOutputStream();

  try {
    service.files().export(fileId, "text/csv")
              .executeMediaAndDownloadTo(outputStream);
} catch (IOException e) {
    System.out.println("Ceva nu a mers bine");
    e.printStackTrace();
}

    System.out.println(outputStream == null);

Any ideea?

Teivaz
  • 5,462
  • 4
  • 37
  • 75
Katelyn
  • 121
  • 2
  • 3
  • 12

1 Answers1

0

Based from this example in Google documentation, I don't see any error with your code.

String fileId = "1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().export(fileId, "application/pdf")
        .executeMediaAndDownloadTo(outputStream);

Make sure that you are using the correct fileId of the specific file you want to download.

You can check on these links: How to get Google Drive file ID, How to download a file from google drive using drive api java?

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59