Send image's and files to cloudinary to get new url

I am trying to do the following.

using appsheet

1. after adding 2 images and 1 file (PDF) I want to send it to cloudinary so they will send me new URLs of the files and save it it google sheet.

I do have this script, but it does not work, my cloudinary info is correct

 

//Function to send files to Cloudinary and get new URLs
function uploadFileToCloudinary(fileUrl) {
  var CLOUD_NAME = "dz-----1h"; // Add your Cloudinary cloud name here
  var cloudinaryURL = "https://api.cloudinary.com/v1_1/" + CLOUD_NAME + "/upload";
  var apiKey = "19-----------73";
  var apiSecret = "C3-----------------------5g";

  var formData = {
    file: fileUrl,
    upload_preset: "YOUR_CLOUDINARY_UPLOAD_PRESET", // Optional, if you're using an upload preset
    api_key: apiKey,
    api_secret: apiSecret
  };

  var options = {
    method: "post",
    payload: formData
  };

  var response = UrlFetchApp.fetch(cloudinaryURL, options);
  var jsonResponse = JSON.parse(response.getContentText());
  var newFileUrl = jsonResponse.secure_url;
  return newFileUrl;
}

// Triggered when a new image or PDF is uploaded to the Google Sheet
function onFormSubmit(e) {
  var sheetName = "Versekering";
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);

  var row = e.range.getRow();
  var column = e.range.getColumn();

  if (column == 5 || column == 6) {
    var fileUrl = e.namedValues["Your File Upload Field Name"][0]; // Replace "Your File Upload Field Name" with the actual field name

    // Upload file to Cloudinary and get new URL
    var newFileUrl = uploadFileToCloudinary(fileUrl);

    // Update columns 5 and 6 with the new URL
    sheet.getRange(row, column).setValue(newFileUrl);
  }
}

 

 

 

0 6 337
6 REPLIES 6


@Odiez wrote:

but it does not work


How does it not work? What does it do? What kind of help are you looking for?

Hi

It does not send images to cloudinary.com when I save the data from appsheet to googlesheet.

I need help on why the script is not working. like I need it to.

1. When saving the data, images and file it does not send it to cloudinary at all.  It show only the file name "Vesekering_Images/63a07ac5.Photo1.031400.png" at the moment

I did make two triggers (on edit)

2. when it does send it, it must get the new url and save them in my google sheet. 

It show only the file name "Vesekering_Images/63a07ac5.Photo1.031400.png" at the moment


It shows that where? What is it supposed to show?

Does the script work if you manually run it? How is Appsheet running the script, a 'call a script' task? Have you checked the audit logs and automation monitor?

 

After reading your response, I went to automation, and click on "call a script", but i cannot find my script the script, there  to use.  Not sure why it does not see it.

https://support.google.com/appsheet/answer/11997142?hl=en

'Call a Script' only works for standalone scripts, yours appears to be a bound script.

For a bound script, onChange() is the only trigger that'll work for Appsheet changes.

Thank you, I have decided to let it go, not get it to work, use my google drive to send it to.

Top Labels in this Space