Drive.Files.insert on shared folder fail. Error: File not found: XXX.

4,258 views
Skip to first unread message

Jorge Forero

unread,
May 27, 2021, 7:01:33 PM5/27/21
to Google Apps Script Community

Hello,

I'm using the Drive API to insert a file in a folder on a shared drive.   When I use the following function on an individual drive, it works fine, but if the folder is a shared drive, I get the following error message:

"No se ha podido llamar a la API drive.files.insert; error: File not found: 1jQNlotN1lrlOXr-g1LqjD70jK2kUoj1x" <<< This is the folder id placed on the shared drive ( FolderTargetId parameter ). The folder exists! on the shared drive.
I've double-checked the scopes but I getting the error. What am I missing?

/**
* convertExcelToSheets
* Convierte el archivo excel dado a Sheets y lo almacena en el folder con Id FolderTargetId
*
* @param {string} ExcelId - Id del excel a convertir
* @param {string} FolderTargetId - Id del folder destino
* @return {string} - Id del archivo convertido
*/
function convertExcelToSheets( ExcelId, FolderTargetId ) {
// Obtiene el archivo Excel
let excelFile = DriveApp.getFileById( ExcelId );
console.log( `excelFile= ${excelFile.getId()}` );
let blob = excelFile.getBlob();
let name = excelFile.getName().split('.')[0];
let newFile = {
title : name + '_CONVERTED',
parents: [ { id: FolderTargetId } ]
};
let sheetFile = Drive.Files.insert( newFile, blob, { convert: true } );
return sheetFile.getId();
};

Thanks in advance for any help.

Jorge.


Le interesa Google Apps Script? 

Mailtrack Sender notified by
Mailtrack 05/27/21, 05:51:14 PM

Clay Smith

unread,
May 27, 2021, 7:08:22 PM5/27/21
to google-apps-sc...@googlegroups.com
Hey Jorge,

Add in the parameter for supportsAllDrives set to true. and ensure you have the permission to add the file to the drive.
The advanced drive services use the v2 API. You can check the reference for further details.

let sheetFile = Drive.Files.insert( newFile, blob, { convert: true, supportsAllDrives: true } );

Clay

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CABPUPFG7Fa5garbQ0bZOk4mgEWg6zieC%3DXwZk_sHBgXUmR4KdA%40mail.gmail.com.


--


Alan Wells

unread,
May 27, 2021, 7:24:41 PM5/27/21
to Google Apps Script Community
@Clay
Do you know what the blob setting should be if there is no blob?
Should the setting be omitted?
Made an empty string?

Drive.Files.insert(resource,"",{ supportsAllDrives: true })

Jorge Forero

unread,
May 27, 2021, 7:31:36 PM5/27/21
to Google Apps Script Community
Hello Clay,

yeah, It works!  Thank you so much.

Greetings,

Le interesa Google Apps Script? 

Mailtrack Sender notified by
Mailtrack 05/27/21, 06:29:33 PM

Clay Smith

unread,
May 27, 2021, 7:43:21 PM5/27/21
to google-apps-sc...@googlegroups.com
If there is no blob you are likely not inserting a file. I’d test for a blob and skip the insert if there isn’t one. 

Clay

On May 27, 2021, at 19:31, Jorge Forero <jorge....@mr-philly.com> wrote:



Alan Wells

unread,
May 27, 2021, 7:49:55 PM5/27/21
to Google Apps Script Community
I use Drive.Files.insert without a blob to create a new empty Sheets file.
I'll run some tests and see what happens.

  resource = {};
  resource.title = "AAA New Sheet";
  resource.mimeType = MimeType.GOOGLE_SHEETS;

  fileJson = Drive.Files.insert(resource);//Create a new blank Sheets file

Alan Wells

unread,
May 27, 2021, 8:24:04 PM5/27/21
to Google Apps Script Community
After testing, I've determined that the blob parameter can take undefined as a setting and create a new blank Sheets file.
  resource = {};
  resource.title = "AAA New Sheet";
  resource.mimeType = MimeType.GOOGLE_SHEETS;

  fileJson = Drive.Files.insert(resource,undefined,{ supportsAllDrives: true });//Create a new blank Sheets file

Reply all
Reply to author
Forward
0 new messages