Tags down


Google Drive encrypt image with Apps Script? (cCryptoGS)

By : user2174584
Date : October 17 2020, 08:10 PM
Does that help I thought that when the binary data is directly used, the corruption of data might occur. So how about this modification?
Modification points: Use the byte array instead of the blob. Modify from getBlob().getDataAsString() to getBytes().toString(). When the data is decoded, the number values are converted to the byte array, and converted to the blob.
code :
function TestEncryption()
  //Add library MSJnPeIon6nzdLewGV60xWqi_d-phDA33 to project to access CryptoGS functions

  var hash = "This is my secret passphrase";
  var cipher = new cCryptoGS.Cipher(hash, 'aes');

  // Encode
  var origFile = DriveApp.getFileById("ID of an example file");
  var mimeType = origFile.getMimeType(); // Added
  var blob = origFile.getBlob().getBytes().toString(); // Modified
  var encryptedBlob = cipher.encrypt(blob);
  var encryptedFile = DriveApp.createFile("ENCRYPTEDTest", encryptedBlob);
  var newBlob = encryptedFile.getBlob().getDataAsString();

  // Decode
  var decryptedBlob = cipher.decrypt(newBlob);
  var b = Utilities.newBlob(decryptedBlob.split(","), mimeType, "DECRYPTEDTest"); // Added
  var decryptedFile = DriveApp.createFile(b); // Modified

Share : facebook icon twitter icon

How to set the image/png mime type in google drive from google apps script?

By : Roman Bolshev
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm afraid this is probably related to this issue with jpegs... The issue has been posted on april 2012 but it's not fixed yet.

Inserting a Google Drive image into a document using Google Apps Script

By : Matyáš Zedníček
Date : March 29 2020, 07:55 AM
it helps some times To insert files from Drive do not use the HTTP route unless the file has been made public via drive hosting
Insert use the built in apis to read the file's blog and insert the img.
code :
function insertImageFromDrive(){
 var fileId = '0B_dyIOzoasdfasdfPVTMxdTVXWDg';
 var img = DriveApp.getFileById(fileId).getBlob();
 DocumentApp.getActiveDocument().getBody().insertImage(0, img); 

Cannot add image from Google Drive to a Google Form using Apps Script

By : user5380795
Date : March 29 2020, 07:55 AM
like below fixes the issue Sorry, I think I posted the wrong code segment, so actually what I am doing is:
code :
var img = DriveApp.getFileById("a_valid_drive_file_id_here");
var imageItem = form.addImageItem();

Can't Display an image from google drive on a dialog or sidebar using google apps script

By : Andrew Watters
Date : March 29 2020, 07:55 AM
With these it helps Using images from Google Drive in Dialog and Sidebars
I think my problem was that I wasn't always using the id from the shareable link and possibly I may have not always set it up to be publicly accessible. I just did this little example and they all work just fine and they include some ways that I had problems getting to work in the past.
code :
<!DOCTYPE html>
    <base target="_top">
    <img src="https://drive.google.com/uc?id=ShareableLinkID&export=download" width="200" />
    <img src="http://drive.google.com/uc?export=view&id=ShareableLinkID" width="200" />
    <img src="https://drive.google.com/uc?id=ShareableLinkID" width="200" />


Inserting an Image From Google Drive or from a URL into Google Sheets with Google Apps Script

By : user3639392
Date : March 29 2020, 07:55 AM
I wish this help you You want to put the image files in your Google Drive to the Spreadsheet using the formula of IMAGE(). In your case, the URL is like https://google.com/image.png and https://drive.google.com/open?id=###. https://google.com/image.png is the external link. https://drive.google.com/open?id=### is the link in your Google Drive. You want to achieve this using Google Apps Script.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
code :
for (var num = 0; num < source.length; num ++) {
  if (/https?:\/\//.test(source[num][0])) { //Check to ensure a URL has been entered.
    var graphicformula = '=IMAGE("' + source[num][0] + '",1)';
for (var num = 0; num < source.length; num ++) {
  if (/https?:\/\//.test(source[num][0])) { //Check to ensure a URL has been entered.
    var res = source[num][0].match(/drive\.google\.com\/open\?id=(\w.+)|drive\.google\.com\/file\/d\/(\w.+)\//);
    if (res && res.length > 0) {
      var id = res[1] || res[2];
      var file = DriveApp.getFileById(id);
      if (file.getOwner().getEmail() != Session.getActiveUser().getEmail()) {
        file = file.makeCopy(DriveApp.getRootFolder());
      file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
      source[num][0] = "https://drive.google.com/uc?export=download&id=" + id;
    var graphicformula = '=IMAGE("' + source[num][0] + '",1)';
    dstSheet.getRange(dstSheet.getLastRow() + 1, 1).setFormula(graphicformula);
var scale = 0.5; // In this case, the imported image is reduces with 50 % from the original size.
var n = 0;
var cellWidth = 0;
for (var num = 0; num < source.length; num ++) {
  if (/https?:\/\//.test(source[num][0])) { //Check to ensure a URL has been entered.
    var res = source[num][0].match(/drive\.google\.com\/open\?id=(\w.+)|drive\.google\.com\/file\/d\/(\w.+)\//);
    var blob = res && res.length > 0 ? DriveApp.getFileById(res[1] || res[2]).getBlob() : UrlFetchApp.fetch(source[num][0]).getBlob();
    var lastRow = dstSheet.getLastRow() + 1 + n++;
    var image = dstSheet.insertImage(blob, 1, lastRow);
    var imageWidth = image.getWidth() * scale;
    var imageHeight = image.getHeight() * scale;
    cellWidth = cellWidth > imageWidth ? cellWidth : imageWidth;
    dstSheet.setRowHeight(lastRow, imageHeight);
dstSheet.setColumnWidth(1, cellWidth);
Related Posts Related Posts :
Privacy Policy - Terms - Contact Us © voile276.org