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);
}
}
User | Count |
---|---|
31 | |
11 | |
3 | |
2 | |
2 |