0

CURRENTLY

I have a 3MB image file that I would like to send to AWS Lambda (via API gateway) from Google Apps Script so the file can be processed.

My Lambda API Gateway Request:

  let bytes = file.getBlob().getBytes();
  console.log("Byte Size:"+bytes.length)

  let payload = {
      bytes: bytes,
      type: "image",
  };

  var options = {
    method: "PUT",
    "Content-Type": "application/json",
    payload: JSON.stringify(payload),
  };

  console.log("Stringified size:"+JSON.stringify(options))

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

ISSUE

The response I get is:

Byte Size:3308814
Stringified size: 11886033

Exception: Request failed for API returned code 413.
Truncated server response: HTTP content length exceeded 10485760 bytes.

QUESTION

What am I doing wrong such that the total package balloons from 3.3MB to over 10.4MB in my payload?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Wronski
  • 1,506
  • 3
  • 18
  • 37
  • Although from your question, unfortunately, I'm not sure about the URL and the specification of the API you want to use, for example, I think that in your `options`, it is required to modify. [Ref](https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetchurl,-params) When you modify it to `var options = {method: "PUT", contentType: "application/json", payload: JSON.stringify(payload)};`, what result will you obtain? If this was not the direct solution to your issue, can you provide the official document of the specification of API you want to use? – Tanaike Jan 08 '22 at 06:25
  • 1
    What's the size of `JSON.stringify(payload)`? – Dunedan Jan 08 '22 at 07:42
  • @Dunedan, that was a good question that I also looked into. 11.8MB for the payload. So, it seems this is more of a Javascript JSON.stringify issue, rather than anything to do with the API. Maybe I will see if there is a way I can send the data without stringifying it. – Wronski Jan 08 '22 at 08:02
  • 3
    Did you try send it as binary data, or string after `base64`? – Marcin Jan 08 '22 at 08:30
  • 2
    Can you try gzipping: `Content-Type: application/javascript; Content-Encoding: gzip;`,https://developers.google.com/apps-script/reference/utilities/utilities#gzipblob – first last Jan 08 '22 at 09:19
  • @marcin, all my code is above. How do if I sent it as binary or string after `base64`? – Wronski Jan 09 '22 at 06:41
  • I *think* I have made some progress. Following example from https://stackoverflow.com/q/38809183/1730260 I was able to send the image file using contentType `multipart/form-data` to my Lambda. But now the body of the request is in an unusual format that I am working out how to use :) – Wronski Jan 09 '22 at 08:06

0 Answers0