I am trying to convert an ods file to google sheets file format. However if the file is a little big (~ 2mb to 3mb) it starts to present the following problem several times
GoogleJsonResponseException: API call to drive.files.insert failed with Internal Error
My code uses a try catcth to keep trying to convert. It can convert after many attempts or it doesn't even convert
var ssOrige = DriveApp.getFileById(fileId)
var ssOrigeBlob = ssOrige.getBlob()
var ssName = ssOrige.getName()
var newFile = {
title : ssName.split('.')[0],
parents: [{id: folderDestinationId}]
}
var ssDestination = null
while(!ssDestination) {
try {
// Cria cópia do arquivo como gSheet
ssDestination = Drive.Files.insert(newFile, ssOrigeBlob, {convert: true})
} catch (e) {
Logger.log(e)
}
}
Small files can have the same problem, but they tend to convert easier and faster
I have some ods files in a folder on the drive. I get the ods file by ID and try to convert it to google sheets format. I use Google App Script to get the file and try to do the conversion. So, I take an ods file that is already in the google drive and try to convert and save it inside the drive
Instead of using the Drive API v2 try to use the Drive API v3.
Look at the
Files.create
and the section to upload new Google Docs types.This code is working fine for me with multiple files of various size: