I've written the following script:
function uploadImageToDiscord() {
var link = "https://i.imgur.com/image.jpg";
var img = UrlFetchApp.fetch(link).getBlob();
var discordUrl = "https://discordapp.com/api/webhooks/mywebhook";
var payload = {
"file": img
};
var params = {
headers: {
"Content-Type": "multipart/form-data"
},
method: "post",
payload: payload,
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(discordUrl, params);
Logger.log(response.getContentText());
}
However, GAS tells me that I'm trying to send an empty message. Can anyone help me?
The error must be related to either the way of me trying to download the image:
var img = UrlFetchApp.fetch(link).getBlob();
or the way of how I define the payload for the multipart/form-data content:
var payload = {
"file": img
};