Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
How do i post a image file with axios to Google Apps Script and attach it to an email and a Google Sheet row?

I have a simple html form in React that i post to my google script. So far i've got it working with simple text (like name, email) and send an email and create a row in google sheets with the data from my form.

But how do i post an image file with axios from my form to the apps script, attach it to an email and add it on a row in my sheet?

js:

handleSubmit(e) {
e.preventDefault();
var form = document.querySelector("form");
var data = new URLSearchParams(new FormData(form)).toString();
console.log(data);

axios
  .post(
    "https://script.google.com/macros/s/[myscripthere]/exec",
    data
  )
  .then(function (response) {
    console.log(response);
  });
}

Apps script:

var TO_ADDRESS = "myemail@gmail.com";

function doPost(e) {

  try {
    Logger.log(e);
    
    var mailData = e.parameters; data
    
    record_data(e);

    MailApp.sendEmail({
      to: TO_ADDRESS,
      subject: "subject text",
      replyTo: String(mailData.email),
      htmlBody: formatMailBody(mailData),
      
    });

    return ContentService
          .createTextOutput(JSON.stringify({"result":"success","data": JSON.stringify(e.parameters) }))
          .setMimeType(ContentService.MimeType.JSON);
  } catch(error) {
    Logger.log(error);
    return ContentService
          .createTextOutput(JSON.stringify({"result":"error", "message": "Sorry, there is an issue with the server."}))
          .setMimeType(ContentService.MimeType.JSON);
  }
}

function record_data(e) {
  Logger.log(JSON.stringify(e));
  try {
    var doc     = SpreadsheetApp.getActiveSpreadsheet();
    var sheetName = e.parameters.formGoogleSheetName || "responses";
    var sheet   = doc.getSheetByName(sheetName); // select the responses sheet
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
    var nextRow = sheet.getLastRow()+1; // get next row
    var row     = [ new Date().toUTCString() ]; // first element in the row should always be a timestamp
    // loop through the header columns
    for (var i = 1; i < headers.length; i++) { // start at 1 to avoid Timestamp column
      if(headers[i].length > 0) {
        row.push(e.parameter[headers[i]]); // add data to row
      }
    }
    // more efficient to set values as [][] array than individually
    sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
  }
  catch(error) {
    Logger.log(error);
    Logger.log(e);
    throw error;
  }
  finally {
    return;
  }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!