OiO.lk Blog javascript Google Apps Script – missing e.postData and BLOB parameters
javascript

Google Apps Script – missing e.postData and BLOB parameters


Could not find any info on my problem below – so posting.

I am uploading a BLOB to a google-apps-script webapp – code and log below.

  1. e.postData is missing on the webapp doPost(e)
  2. e.parameter.**NewsFile** is missing
  3. the e.contentLength indicates the data is received – checked with 1Mb BLOB
  4. the client side formdata indicates NewsFile is being attached
  5. chrome.devtools show correct payload sent to server

I am using FormData because I need to programatically attach files/blobs to the send request.

Any ideas/insight greatly appreciated.

// client code  
function clientTest() {  
    const content="<q id="a"><span id="b">hey!</span></q>";  
    const blob = new Blob([content], { type: "text/xml" });  
    const formdata = new FormData();  
    formdata.append("TestKey", "TestValue");  
    formdata.append("NewsFile", blob);  
    console.log(`client send info :: ${[...formdata.keys()].join(" | ")}`);  
    fetch("webappurl", { method: "POST", body: formdata });  
}  

// client log  
// client send info :: TestKey | NewsFile


// server code - google apps script webapp 
function doPost(e) {
    console.info(`e.keys = ${[...Object.keys(e)].join(" | ")}`);
    console.info(`param.keys = ${[...Object.keys(e.parameter)].join(" | ")}`);
    console.info(`post.length = ${e.contentLength}`); 
}    

// server log
// e.keys = parameters | contextPath | parameter | contentLength | queryString | pathInfo  
// param.keys = TestKey  
// post.length = 684



You need to sign in to view this answers

Exit mobile version