I have tried some functions of Google drive, but I couldn't able to download the file from Drive.
Here is the code which I used
private static InputStream downloadFile(Drive service, File file) {
if (file.getDownloadUrl() != null && file.getDownloadUrl().length() > 0) {
try {
HttpResponse resp =
service.getRequestFactory().buildGetRequest(new GenericUrl(file.getDownloadUrl()))
.execute();
return resp.getContent();
} catch (IOException e) {
// An error occurred.
e.printStackTrace();
return null;
}
} else {
// The file doesn't have any content stored on Drive.
return null;
}
}
When I ran the script it shows file.getDownloadUrl()
is NULL.
What did I miss here?
Now it's executing after adding the following line before I call the download function
File file1 = service.files().get(fileid).execute();
downloadFile(service,file1);
Now the problem is how to download the file with the help of 'response' which I got from the script....