Upload Image through HTTP POST Request

Hi,

In one my apps I am using PUSHOVER api to send notifications. I am using HTTP POST for the API. Its working fine. But now i have a requirement to send an image along with the HTTP POST request. Is it possible. The image should be actual byte data and not url of image. Can I upload the actual binary data of image within the JSON content. Below is the documentation given by them but it is not for JSON format. Can a similar thing be done within JSON or any other method within appsheet

jyothis_m_0-1669282770831.png

Below is what i normally use inside the JSON Body. I need to add attachment in this code. Can someone help me with this.

{
"token": "asdfghjkl",
"user": "lkjhgfdsa",
"title":"<<[Title]>>",
"message": "<<[Body]>>",
"sound":"bike",
"url":"<<"https://www.appsheet.com/start/123456789"&[DeepLink]>>",
"url_title":"View Full Details"
}

Solved Solved
1 7 1,089
1 ACCEPTED SOLUTION

Hello @jyothis_m . Tried to create a set up and successfully made it. 

Here are the details 

Here is the formula to get the image link  from virtual columm

CONCATENATE( "https://www.appsheet.com/template/gettablefileurl","appName=",ENCODEURL(CONTEXT("AppName")), "&tableName=",ENCODEURL(CONTEXT("Table")),"&fileName=",ENCODEURL([Image]))

App must disable to security setting in order to fetch the image

AngeloParana_0-1669742846939.png

 

Here is log of image link successfully fetch

AngeloParana_1-1669742908196.png

Create an automation to appscript

AngeloParana_2-1669742960851.png

 

Here is the appscript code 

 

function form_data(e) {

var youtubeLogoUrl =e;

Logger.log(e)

var file = UrlFetchApp

                         .fetch(youtubeLogoUrl)

                         .getBlob()

                         .setName("youtubeLogoBlob");

 var url = "https://api.pushover.net/1/messages.json";

 

  var form = {

    token : "apri2xcbvwnbstrzsssu85tosq9i33",

    user : "ucw7i37vs8c65bbc4d9nxnv698esj4",

    device : "21091116ag",

    title : "Backup finished - SQL1",

    message : " Backup of database example finished in 16 minutes.",

    attachment : file

    };

  send_pushover(url,form);

}

 

function send_pushover(url,form) {

  var options = {

    method : "POST",

    payload : form

  };

  var response = UrlFetchApp.fetch(url,options);

  Logger.log(response)

}

Test result 

Screenshot_2022-11-30-01-17-24-763_lockscreen.jpg

โ€ƒ

Hope you understand it. 

 

 

 

 

 

View solution in original post

7 REPLIES 7

You can easily do it via appscript. You need to create I think blob oject. Attached as one of the parameters. 

Hi @AngeloParana Thanks for the reply. But how do i get the image from appsheet to appscript. I tried the API separately with form-data body and image is sending successfully. Is there a similar way possible in JSON body.

Hello @jyothis_m  You may check on this thread how to get the file lin

https://www.googlecloudcommunity.com/gc/Announcements/Call-to-Action-for-Apps-Constructing-URLs-to-G...

Then use Urlfetchapp to pass the value like this 

IMG_20221124_212903.jpg

โ€ƒ

 

 

 

 

 

 

 

 

 

 

Thank you @AngeloParana  Shall try this

Hi @AngeloParana I tried but didn't succeed. I have very little knowledge in coding, Below is the code i am using in appscript, can you please guide me to implement it. The notification is reaching correctly but no attachment. Can you help me where I am going wrong.

 

function Pushover(){
// Make a POST request with a JSON payload.
var data = {
'token': 'asdfghjkl',
'user': 'lkjhgfdsa',
'title':'Image Notification Test',
'message': 'Test Message',
'sound':'Bike',
'attachment':{
'filename':'test.jpg',
'Content-Type':'image/jpeg',
}
};
var options = {
  'method' : 'post',
  'contentType': 'application/json',
  // Convert the JavaScript object to a JSON string.
  'payload' : JSON.stringify(data)
};
UrlFetchApp.fetch('https://api.pushover.net/1/messages.json', options);
}

 

Hello @jyothis_m . Tried to create a set up and successfully made it. 

Here are the details 

Here is the formula to get the image link  from virtual columm

CONCATENATE( "https://www.appsheet.com/template/gettablefileurl","appName=",ENCODEURL(CONTEXT("AppName")), "&tableName=",ENCODEURL(CONTEXT("Table")),"&fileName=",ENCODEURL([Image]))

App must disable to security setting in order to fetch the image

AngeloParana_0-1669742846939.png

 

Here is log of image link successfully fetch

AngeloParana_1-1669742908196.png

Create an automation to appscript

AngeloParana_2-1669742960851.png

 

Here is the appscript code 

 

function form_data(e) {

var youtubeLogoUrl =e;

Logger.log(e)

var file = UrlFetchApp

                         .fetch(youtubeLogoUrl)

                         .getBlob()

                         .setName("youtubeLogoBlob");

 var url = "https://api.pushover.net/1/messages.json";

 

  var form = {

    token : "apri2xcbvwnbstrzsssu85tosq9i33",

    user : "ucw7i37vs8c65bbc4d9nxnv698esj4",

    device : "21091116ag",

    title : "Backup finished - SQL1",

    message : " Backup of database example finished in 16 minutes.",

    attachment : file

    };

  send_pushover(url,form);

}

 

function send_pushover(url,form) {

  var options = {

    method : "POST",

    payload : form

  };

  var response = UrlFetchApp.fetch(url,options);

  Logger.log(response)

}

Test result 

Screenshot_2022-11-30-01-17-24-763_lockscreen.jpg

โ€ƒ

Hope you understand it. 

 

 

 

 

 

You are Amazing!!! ๐Ÿค @AngeloParana It worked flawlessly. Thanks a lot for your help. I was struggling with the code needed in GAS. Thanks once again. ๐Ÿค—

Top Labels in this Space