简体   繁体   中英

Is there a limit on the size of the blob for insertImage into a sheet (Google App Script)?

I am inserting images on my google drive into sheets via their ID's.

However, when executing the code it always throws:

We're sorry, a server error occurred. Please wait a bit and try again. (line XX, file "TestCodeV1.0")

Where line XX has the code for insertImage(blobSource, column, row) .

I have tested the FILE_ID of different images on my GDrive, and it works for images smaller or equal to 151 239 bytes , ( img.getSize ). For images larger than that it just throws the same error.

I have tried adding a delay between getFileByID and insertImage , however, that did not help (Thought it might be a 'still loading image blob' type of error).

I have tried to see if it is related to the images' pixel count or width/height.

The only factor seems to be the size (151 239 bytes)

var SPREADSHEET_URL = 'YOUR_SHEET_ID_HERE'
var SHEET_NAME= 'YOUR_SHEET_NAME_HERE'
var FILE_ID= 'YOUR_IMAGE_ID_HERE'

var ss = SpreadsheetApp.openById(SPREADSHEET_URL);
var sheet = ss.getSheetByName(SHEET_NAME);

var img = DriveApp.getFileById(FILE_ID).getBlob();
var image = sheet.insertImage(img, 1,1);

I expected the images the work be inserted easily. However, any image larger than 147KB failed with an error: "We're sorry, a server error occurred. Please wait a bit and try again."

Solved by Tanaike - Find full explanation HERE

Summary

Images that are inserted with insertImage() must have a pixel area less than 1 048 576 px^2

Some examples of maximum pixel dimenions:

  • 1024 pixels x 1024 pixels
  • 2048 pixels x 512 pixels
  • 4096 pixels x 256 pixels

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM