I am new to SO.
I am trying to hit an api using put request to upload the images and I wanted to do it using google sheets and google apps script. I am able to add images from url to the sheet but not to the api because it accepts only .png/.jpeg format and I think currently it is going in blob format. Not sure.
Can anyone please help me on how to send image to api using google apps script and sheet.
I am able to get success response using postman when in params I type image as key (filetype) and then upload image from device.
Here is some code that I am using to achieve the above:
function insertImageOnSpreadsheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var response = UrlFetchApp.fetch('Enter URL Here');
var binaryData = response.getContent();
// Insert the image in cell A1.
var blob1 = Utilities.newBlob(binaryData, 'image/png', 'MyImageName');
Logger.log(blob1)
var apiHeaders =
{
"Content-Type":"application/json",
"Authorization":"Enter Token here"
}
var formData= '{"image": "'+blob1+'"}'
var eventApiResponse = callApi('Enter API Here',"put",formData,apiHeaders,"insertImageOnSpreadsheet");
Logger.log(eventApiResponse)
sheet.insertImage(blob1, 1, 3);
}
function callApi(targetURL, method, formData, headers,functionName) {
var options = {
"method": method,
"payload":formData,
"headers":headers}
var response = UrlFetchApp.fetch(targetURL, options);
return response;
}
API : livestream.com/developers/docs/api/#update-event-logo-poster
Somebody pleaasseee help
var formData = Utilities.newBlob(binaryData, 'image/png', 'MyImageName').getBytes()orvar formData = JSON.stringify({image: Utilities.newBlob(binaryData, 'image/png', 'MyImageName').getBytes()}). If those were not the direct solution, I apologize. - TanaikeThe API says unsupported file type, for example, how about base64? - Tanaike