App Sheet image URL error caught in Apps Script

We encountered an image URL failure error in two scenarios in App Sheet:

First Case:

- Sometimes, duplicate images are created with the same file name, but one of them has a size of 0 KB.
- As a result, the image does not display in the app, and the App Sheet image URL with a signature cannot be used for inserting the image into Google slide when creating a presentation using Apps Script.
- When we paste the image URL into a browser, it returns an error in HTML format.
Please check the following error message and code:

Code:
Slides. Presentations. batch Update ({
      requests: requests
    }, copy. get Id());

"requests" array contains the create image requests for insert images in google slide.

Error:

 { [API call to slides. presentations. batch Update failed with error: Invalid requests[110].create Image: The provided image was not found.]
  details:
   { code: 400,
     message: 'Invalid requests[110].create Image: The provided image was not found.' } }

Second Case:

- This issue occurs when fetching images using the fetch All method to retrieve image blobs.
In this case, the image URLs open correctly in a browser, and images are displayed in the app. - Also status code of image URL is 200.

Please check the following error message and code:

Code:

const image_blob_array = URL Fetch App. fetch All(images_URLs);
"images URLs" is an array of app sheet image URLs.

Error:

 { [: API call to slides. presentations. batch Update failed with error: Invalid requests[87].create Image: There was a problem retrieving the image. The provided image should be publicly accessible, within size limit, and in supported formats.]
  name: 'Google Response Exception',
  details:
   { code: 400,
     message: 'Invalid requests [87].create Image: There was a problem retrieving the image. The provided image should be publicly accessible, within size limit, and in supported formats.' } }

Anybody know a solution for this?

Thanks in advance.

0 1 85
1 REPLY 1

First Case: Duplicate Images with 0 KB Size

Possible Causes:

  1. File Corruption or Incomplete Upload โ€“ AppSheet may sometimes create duplicate files, but one of them remains empty (0 KB).
  2. Restricted Access โ€“ The signed AppSheet URLs may expire or be inaccessible to external services like Google Slides.
  3. Incorrect URL Formatting โ€“ Some AppSheet image URLs require special encoding.

Potential Solutions:

Ensure Image Upload Completeness

  • Try manually uploading images and see if the issue persists. If yes, check how AppSheet handles duplicate uploads.

Use Google Drive Public URLs Instead of AppSheet URLs

  • If your images are stored in Google Drive, you may need to convert AppSheet image URLs to publicly accessible Google Drive links.

You can generate a public link via Apps Script:
function getDriveImageUrl(fileId) {

    return "https://drive.google.com/uc?id=" + fileId;}

  •  Replace fileId with the correct Drive file ID.

Check Image URL in Incognito Mode

  • Copy the image URL and paste it into an incognito browser.
  • If it doesnโ€™t load, then AppSheetโ€™s URL is not publicly accessible.

Re-Upload the Image When 0 KB is Detected

  • Modify your script to detect and re-upload any 0 KB images.

 

Second Case: Fetching Images Using fetchAll Method

Possible Causes:

  1. URL Access Restrictions โ€“ Some AppSheet image URLs require authentication.
  2. Size or Format Issue โ€“ Google Slides has limits on image size and supported formats.
  3. AppSheet URL Signing Issue โ€“ If URLs have signatures, they might expire before the script accesses them.

Potential Solutions:

 Test URLs in Apps Script Before Sending to Google Slides
Run this test script:

function testImageUrls() {

  var urls = ["YOUR_APPSHEET_IMAGE_URL"];

  var response = UrlFetchApp.fetch(urls[0]);

  Logger.log(response.getResponseCode());  // Should return 200

  Logger.log(response.getHeaders());}

 

  • If getResponseCode() is not 200, the URL might have restricted access.

 Convert AppSheet URLs to Public URLs

  • Instead of using AppSheetโ€™s signed URLs, consider copying images to Google Drive and using a shareable link.

Example Apps Script to move images to Drive:
function saveImageToDrive(imageUrl) {

    var response = UrlFetchApp.fetch(imageUrl);

    var blob = response.getBlob();

    var folder = DriveApp.getFolderById("YOUR_FOLDER_ID");

    var file = folder.createFile(blob);

    return file.getId(); // Return the file ID for further use}

Reduce Image Size

  • Google Slides might reject large images. Try compressing them before inserting.

Use Individual UrlFetchApp.fetch Instead of fetchAll

  • fetchAll() processes multiple requests simultaneously, but sometimes one failing URL can affect others.

Instead, try fetching URLs one by one:
for (var i = 0; i < image_URLs.length; i++) {

    var response = UrlFetchApp.fetch(image_URLs[i]);

    if (response.getResponseCode() == 200) {

        var blob = response.getBlob();

        // Process and insert into Google Slides }}