I’ve never done what you describe using Apps Script, but have created similar automations using other tools. In any case, I assume you’re on the right track here. Assuming your file is in Google Drive, my guess is that you can use the filepath and filename to get the file id and contents for encoding (via an Apps Script function or maybe a library that someone has published) to the format that can be included in an API request. See whether the Solved: convert data column of type file to base64 on uplo… - Google Cloud Community conversation provides some applicable guidance.
thanks for the instructions…good to know that im near the end.
i started appsheet cause “no or low code”, and now im going crazy trying to conect apps scripts to a external rest api…i read the topic you sent…but i confess… it would be great a more detailed explanation of the steps to convert or to encode.
I have a script that takes a generated xlsx file from Appsheet and converts it into a Google Sheets file for further processing.
I know WHERE Appsheet is storing the xlsx file and I know that it is generated with a unique filename. It MUST be a unique filename inside the folder.
reportsheetdata is the filename (without the path as the path is known to be a GDrive folder) that is passed into the function convertXSLXtoSheet()
Now I am leaving the full script as shown in case any others would like to take the rest of the functionality that it does (converting to GSheets), but the part you may be interested in is how the file is grabbed as a BLOB of data. I would guess that your API endpoint is expecting this rather than a path? The code uses this BLOB as an input to the Drive.Files.Insert method.
Hope I haven’t completely misinterpreted this question and that you can gain some insights from it. You could return blob; instead of the return sheetFile.getId() to just grab the file data and pass it onto your API endpoint.
function convertXLSXtoSheet(reportsheetdata) {
var xlsxfile = DriveApp.getFolderById(appsheettempfolder).getFilesByName(reportsheetdata + ".xlsx").next();
var name = xlsxfile.getName().split('.')[0];
var id = xlsxfile.getId();
Logger.log(id);
var blob = xlsxfile.getBlob();
var newFile = {
title: name + '_converted',
parents: [{ id: appsheettempfolder }]
};
var sheetFile = Drive.Files.insert(newFile, blob, { convert: true, supportsAllDrives: true });
xlsxfile.setTrashed(true);
return sheetFile.getId();
}