V
V
Viktor Familyevich2021-10-07 11:02:17
Google Apps Script
Viktor Familyevich, 2021-10-07 11:02:17

How to send an image via POST request?

Good afternoon.
Google Apps Script has a script that takes an attachment (picture) from a letter and sends it in a post request to the site:

var attachment = message.getAttachments()[0]
var header = {
        'Authorization': 'Basic ' + encoded,
        'Cookie': cookies.join(';')
      };
var payload = {
        "headPicture": attachment2,
        "Name": title,
        "pageType": "news",
      };
      var opt = {
        'method': 'post',
        'headers': header,
        'payload': payload
      };
      var response = UrlFetchApp.fetch("https://www.site.ru/admin/add", opt);

The server returns an error. Please tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
calculator212, 2021-10-07
@calculator212

I think this will help the section - Uploading files with multipart / form-data (there are some features when uploading pictures and more or less large files)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question