I just used 7-zip as suggested above. It worked, but there was an error message for one of the files. It turned out that the filename was invalid for windows -- it had an embedded slash. The zip file was usable, and included all of the other files. Once I fixed the file name on the google drive folder, the download worked correctly.
So it makes sense that there would be problems with a zip file that include a file with an invalid name. But it would have been good if Windows could have supplied a bit more information about the problem.
Here's a part of my code (cannot share all of it) that gets a list of urls and makes a copy on hard drive:
if (Download == TRUE) {
urls = DataFrame$productimagepath
for (url in urls) {
newName <- paste ("Academy/",basename(url), sep =" ")
download.file(url, destfile = newName, mode = "wb")
}
}
You don't have to go for export options in the API since the pdf file is just available in the drive and there is no conversion happening from Google doc format to any convertion format like pdf. That's why you are getting on getting export links. You can download the file by placing a Http Get request through API directly as shown belowNPE
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;
}
}
You have to create a instead of FileOutputStream to create a file with the ByteArrayOutputStream. Below snippet may helpInputStream
OutputStream outputStream = new FileOutputStream(new File("/home/input.pdf"));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
Ensure that you flush the and close both the streams after use.OutputStream
Note : I got to this detailed answer after discussion with OP in chat. To make it simple, OP used instead of ByteArrayOutputStream to create the pdf file. Hope this helps someone passes by!FileOutputStream