1

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

  • 1
    In order to test and replicate your situation, can you provide a sample `ods file`? – Tanaike Dec 11 '20 at 00:35
  • Adding to @Tanaike request please try to explain what is exactly what are you doing. Is this being executed in node.js? Are you getting the file from a browser application with js? – Raserhin Dec 11 '20 at 08:46
  • @Raserhin 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 – Diego Resende Dec 11 '20 at 13:10

1 Answers1

1

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:

function myFunction() {
  let id = "<YOUR ODS FILE ID>";
  let file = DriveApp.getFileById(id);

  let fileBlob = file.getBlob();


  newFile = {
    name: "New File",
    mimeType: "application/vnd.google-apps.spreadsheet"
  }

  try{
    Drive.Files.create(newFile, fileBlob);
  }catch(e){
    Logger.log("Error");
    Logger.log(e);
  }
}
Raserhin
  • 2,516
  • 1
  • 10
  • 14