Appsheet to apps script - upload file

Hi all,

is it possible to appsheet automation to send a file.pdf to a external service using a rest api(urlfetch) ?

let me try to explain better my problem... the automation flow is :

1- document generated by automation (pdf file)

2 - next step is to send the pdf file  to a external services via API. and here is the problem...

see api requirments...

header 

//{ "Content-Type": "multipart/form-data;", "tokenAPI": "{token-user}" }

body

//{ "file": "FILE(form-data)"}

--------------------------------------------------------------------------------------------

here is my sript

leonardorio021_0-1664398644256.png

[Relatรณrio] is a virtual columm with the document path .......example "G:/inspectionfiles/inspection01.pdf"

leonardorio021_1-1664398836758.png

im studyng about the content type, abou base64, but not certain how to solve this...

is it possible to do this automation, passing a columm value ( the file ) or i need to write diferent code ?

 

 
Response code is 400.0
 
Informaรงรฃo
//{"message":"File empty. Check the document path."}

many thanks

0 5 603
5 REPLIES 5

sorry...trying payload = relatorio  ...not Relatรณrio


@leonardorio021 wrote:

im studyng about the content type, abou base64, but not certain how to solve this...


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.

yes ...the file is on google drive.


@dbaum wrote:

I've never done what you describe using Apps Script


and can't provide any better guidance than @Koichi_Tsuji's extensive explanation in the conversation I linked to.

I'll try my luck here with this suggestion.

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 = {
    titlename + '_converted',
    parents: [{ idappsheettempfolder }]
  };
  var sheetFile = Drive.Files.insert(newFileblob, { converttruesupportsAllDrivestrue });
  xlsxfile.setTrashed(true);
  return sheetFile.getId();
}
Top Labels in this Space