I would like to export a native Google spreadsheet/document/drawing/presentation file to another format, in that same folder, using Google Apps Script. I have enabled Advanced Drive Service, and looked at the instructions to Open and Convert Google Docs in your app.
Was hoping I could use Export to get a File which I could then save/rename using Insert.
Trying to achieve something like:
var file = {fileId: "1yDe...lD2U",
folderId: "0B_...hZ1k",
mimetype:"application/vnd.google-apps.document",
targetMimetype:"application/pdf",
targetName:"my converted document"}
var newFile = Drive.Files.export(file.fileId, file.targetMimetype)
// results in error message:
// "Export requires alt=media to download the exported content."
// I am sure the above is incomplete, but unsure how to actually
// save the exported file, in the correct location, with correct filename
Update: when adding alt=media to the call (var newFile = Drive.Files.export(file.fileId, file.targetMimetype, {alt: "media"})
), then the script exits with error code 200 and shows the PDF content in the error message. Similar to issue 6573.
Update: this may not have been clear enough, I want to convert from/to all of the formats listed in the Advanced Drive page, not just to PDF. And the DriveApp getAs documentation states that DriveApp can convert mostly to PDF and images. Hence the focus on using Advanced Drive instead of DriveApp.