How to Copy All Images from Doc into your Google Drive apps script blob file creator

Copy All Images from Doc into your Google Drive

Example will extract all the images from a Google Doc and make copies of them directly into your Google Drive.

function onOpen(){

 DocumentApp.getUi()

 .createMenu(‘images’)

 .addItem(‘creator’,’getImgs’)

 .addToUi()

}

function getImgs(){

 const doc = DocumentApp.getActiveDocument();

 const body = doc.getBody();

 const images = body.getImages();

 const id = ‘1mW6Yh2X4wU8A-vQs1Z2RRVHIfHD_SI3u’;

 const folder = DriveApp.getFolderById(id);

 images.forEach((img,ind) =>{

   const blob = img.getBlob().copyBlob();

   blob.setName(`Image ${ind+1}.jpg`).setContentTypeFromExtension();

   folder.createFile(blob);

 })

 //Logger.log(images);

}

Leave a Comment