Last active
September 19, 2023 08:31
-
-
Save xtman/50a8c5f06532d9878d02a12a2a8d4555 to your computer and use it in GitHub Desktop.
Google App Script: Upload Multiple Files to Google Drive (Code.gs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doGet() { | |
return HtmlService.createHtmlOutputFromFile('Form').setSandboxMode( | |
HtmlService.SandboxMode.IFRAME); | |
} | |
function createFolder(parentFolderId, folderName) { | |
try { | |
var parentFolder = DriveApp.getFolderById(parentFolderId); | |
var folders = parentFolder.getFoldersByName(folderName); | |
var folder; | |
if (folders.hasNext()) { | |
folder = folders.next(); | |
} else { | |
folder = parentFolder.createFolder(folderName); | |
} | |
return { | |
'folderId' : folder.getId() | |
} | |
} catch (e) { | |
return { | |
'error' : e.toString() | |
} | |
} | |
} | |
function uploadFile(base64Data, fileName, folderId) { | |
try { | |
var splitBase = base64Data.split(','), type = splitBase[0].split(';')[0] | |
.replace('data:', ''); | |
var byteCharacters = Utilities.base64Decode(splitBase[1]); | |
var ss = Utilities.newBlob(byteCharacters, type); | |
ss.setName(fileName); | |
var folder = DriveApp.getFolderById(folderId); | |
var files = folder.getFilesByName(fileName); | |
var file; | |
while (files.hasNext()) { | |
// delete existing files with the same name. | |
file = files.next(); | |
folder.removeFile(file); | |
} | |
file = folder.createFile(ss); | |
return { | |
'folderId' : folderId, | |
'fileName' : file.getName() | |
}; | |
} catch (e) { | |
return { | |
'error' : e.toString() | |
}; | |
} | |
} |
I run this script and it upload only 35 files, no more. It was Uncaught.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Buenos dias realizando pruebas con el código me carga la información pero se está perdiendo en el momento de almacenarla, ¿algún cambio que se deba realizar? , agradecería su ayuda