I'm trying to call this upload script in an html alert
in the spreadsheet:
drive-multi-upload
For that I'm using this function in the Code.gs
file:
function showDialog(){
const TEMPLATE = HtmlService.createTemplateFromFile('forms'); // calls the html page where the alert template will be
const HTML = TEMPLATE.evaluate().setWidth(600).setHeight(400); // we prepare the template to be loaded
SpreadsheetApp.getUi().showModalDialog(HTML, " "); // we load the template on the screen
}
The issue is that if another account clicks the button to upload the file, the message Exception: Unable to retrieve the next object: the iterator has reached the limit.
is displayed.
How can I resolve this?
Edit:
looking at the execution log I have this here:
Exception: Unfortunately, a server error has occurred. Wait a moment and try again.
at getParent(Code:12:25)
at eval([unknown file]:110:56)
at eval([unknown file]:368:3)
at doGet(Code:2:59)
My Code.gs
file is exactly like this:
function doGet(e) {
return HtmlService.createTemplateFromFile('forms.html').evaluate();
}
function getOAuthToken() {
return ScriptApp.getOAuthToken();
}
function showDialog(){ //for show the msg to the user
const TEMPLATE = HtmlService.createTemplateFromFile('forms');// chama a página do html onde estará o template do alerta
const HTML = TEMPLATE.evaluate().setWidth(600).setHeight(400);// preparamos o template para ser carregado
SpreadsheetApp.getUi().showModalDialog(HTML, " ");// carregamos o template na tela
}
function getParent(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var id = ss.getId();
var parent = DriveApp.getFileById(id).getParents().next().getId();
return parent
}
// função para executar um script no mobile
function onEdit(e) {
if (e.range.getA1Notation() == 'A1') {
if (/^\w $/.test(e.value)) {
eval(e.value)();
e.range.clear();
}
}
}
/**
* creates a folder under a parent folder, and returns it's id. If the folder already exists
* then it is not created and it simply returns the id of the existing one
*/
function createOrGetFolder(folderName, parentFolderId) {
try {
var parentFolder = DriveApp.getFolderById(parentFolderId),
folder;
if (parentFolder) {
var foldersIter = parentFolder.getFoldersByName("Video");
if (foldersIter.hasNext()) {
video_folder = foldersIter.next().getFoldersByName(folderName); //folderName esta definido no arquivo forms.html
if (video_folder.hasNext()) {
folder = video_folder.next();
}
} else {
folder = parentFolder.createFolder("Video");
folder = folder.createFolder(folderName);
}
} else {
throw new Error("Parent Folder with id: " parentFolderId " not found");
}
return folder.getId();
} catch (error) {
return error;
}
}
// NOTE: always make sure we use DriveApp, even if it's in a comment, for google to import those
// libraries and allow the rest of the app to work. see https://github.com/tanaikech/Resumable_Upload_For_WebApps
CodePudding user response:
I'm writing this answer as a community wiki since the solution was provided by the OP and @TheWizEd in the comments section.
The issue was related to the permissions of Google Drive that do not allow the script to create folders inside his structure since his users do not have access to the main folder.
The solution was to share the main folder with the users.
As an extra, I searched if there was an option to allow apps script to run as a specific user, and you might try impersonation. However, there is no direct library from Google for impersonation in Apps Script; you will need to search for 3rd party.